From 9e14183ac72283e0fe1188252246b5a68934d2bf Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Thu, 6 Mar 2025 15:59:17 +0700 Subject: [PATCH] test websocket --- package.json | 4 +- src/app.ts | 53 +- src/controllers/ReportController.ts | 4200 +++++++++++++++------------ 3 files changed, 2334 insertions(+), 1923 deletions(-) diff --git a/package.json b/package.json index f31b73c..364e8b7 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@types/node": "^20.11.5", "@types/node-cron": "^3.0.11", "@types/swagger-ui-express": "^4.1.6", + "@types/ws": "^8.5.14", "nodemon": "^3.0.3", "prettier": "^3.2.2", "ts-node": "^10.9.2", @@ -47,6 +48,7 @@ "swagger-ui-express": "^5.0.0", "tsoa": "^6.0.1", "typeorm": "^0.3.19", - "typeorm-cli": "^1.0.7" + "typeorm-cli": "^1.0.7", + "ws": "^8.18.1" } } diff --git a/src/app.ts b/src/app.ts index 40aeda3..9cb9002 100644 --- a/src/app.ts +++ b/src/app.ts @@ -10,6 +10,14 @@ import { RegisterRoutes } from "./routes"; import logMiddleware from "./middlewares/logs"; import axios from "axios"; +import http from "http"; +import { WebSocket, WebSocketServer } from "ws"; // ✅ Import WebSocket + +// ✅ สร้าง WebSocket Server โดยใช้ HTTP Server เดียวกัน +export const wss = new WebSocketServer({ noServer: true }); + + + async function main() { await AppDataSource.initialize(); @@ -18,7 +26,7 @@ async function main() { app.use( cors({ origin: "*", - }), + }) ); app.use(express.json()); app.use(express.urlencoded({ extended: true })); @@ -56,7 +64,7 @@ async function main() { accept: "application/pdf", }, responseType: "arraybuffer", - }, + } ); console.log("Response:", apiResponse.data); @@ -75,16 +83,49 @@ async function main() { RegisterRoutes(app); app.use(error); + app.use(cors()); const APP_HOST = process.env.APP_HOST || "0.0.0.0"; const APP_PORT = +(process.env.APP_PORT || 3000); - app.listen( + // ✅ สร้าง HTTP Server และเชื่อม Express + const server = http.createServer(app); + + // ✅ WebSocket Handling + wss.on("connection", (ws) => { + console.log("✅ WebSocket Client Connected"); + // clients.add(ws); // เก็บ client ไว้ + + // ✅ ตั้ง Heartbeat (ping/pong) + + ws.on("message", (message) => { + console.log("📩 Received:", message.toString()); + ws.send("📡 Server Received: " + message.toString()); + }); + + ws.on("close", () => { + console.log("❌ WebSocket Client Disconnected"); + }); + }); + + // ✅ อัปเกรด HTTP เป็น WebSocket + server.on("upgrade", (req, socket, head) => { + wss.handleUpgrade(req, socket, head, (ws) => { + wss.emit("connection", ws, req); + }); + }); + + server.listen( APP_PORT, APP_HOST, () => ( - console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`), - console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`) - ), + console.log( + `[APP] Application is running on: http://localhost:${APP_PORT}` + ), + console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`), + console.log( + `[WS] WebSocket Server is running on ws://localhost:${APP_PORT}` + ) + ) ); } diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index a75a528..9f7f9f1 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1,1949 +1,2317 @@ -import { Controller, Route, Security, Tags, Body, Request, Response, Get, Query, Put, Post, Path } from "tsoa" -import { AppDataSource } from "../database/data-source" -import HttpSuccess from "../interfaces/http-success" -import HttpStatusCode from "../interfaces/http-status" -import HttpError from "../interfaces/http-error" -import { RequestWithUser } from "../middlewares/user" -import { DataPass, setLogDataDiff } from "../interfaces/utils" -import { Personal } from "../entities/Personal" -import { Assign } from "../entities/Assign" -import { EvaluateChairman } from "../entities/EvaluateChairman" -import { EvaluateResult } from "../entities/EvaluateResult" -import { EvaluateAssessor } from "../entities/EvaluateAssessor" -import { AssignDirector } from "../entities/AssignDirector" -import { EvaluateAchievement } from "../entities/EvaluateAchievement" -import { EvaluateCommander } from "../entities/EvaluateCommander" -import CallAPI from "../interfaces/call-api" -import { Between, Double, In, IsNull, Not } from "typeorm" -import Extension from "../interfaces/extension" -import { Appoint } from "../entities/Appoint" -import { AppointDirector } from "../entities/AppointDirector" -import { AssignOutput } from "../entities/AssignOutput" - +import { + Controller, + Route, + Security, + Tags, + Body, + Request, + Response, + Get, + Query, + Put, + Post, + Path, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatusCode from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { RequestWithUser } from "../middlewares/user"; +import { DataPass, setLogDataDiff } from "../interfaces/utils"; +import { Personal } from "../entities/Personal"; +import { Assign } from "../entities/Assign"; +import { EvaluateChairman } from "../entities/EvaluateChairman"; +import { EvaluateResult } from "../entities/EvaluateResult"; +import { EvaluateAssessor } from "../entities/EvaluateAssessor"; +import { AssignDirector } from "../entities/AssignDirector"; +import { EvaluateAchievement } from "../entities/EvaluateAchievement"; +import { EvaluateCommander } from "../entities/EvaluateCommander"; +import CallAPI from "../interfaces/call-api"; +import { Between, Double, In, IsNull, Not } from "typeorm"; +import Extension from "../interfaces/extension"; +import { Appoint } from "../entities/Appoint"; +import { AppointDirector } from "../entities/AppointDirector"; +import { AssignOutput } from "../entities/AssignOutput"; +import { WebSocket } from "ws"; +import { wss } from "../app"; // ✅ Import clients @Route("api/v1/probation/report") @Tags("Report") @Security("bearerAuth") -@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง" +) export class ReportController extends Controller { - private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman) - private evaluateResultRepository = AppDataSource.getRepository(EvaluateResult) - private personalRepository = AppDataSource.getRepository(Personal) - private evaluateAssessorRepository = AppDataSource.getRepository(EvaluateAssessor) - private assignDirectorRepository = AppDataSource.getRepository(AssignDirector) - private evaluateAchievementRepository = AppDataSource.getRepository(EvaluateAchievement) - private evaluateCommanderRepository = AppDataSource.getRepository(EvaluateCommander) - private appointRepository = AppDataSource.getRepository(Appoint) - private AppointDirectorRepository = AppDataSource.getRepository(AppointDirector) - private assignRepository = AppDataSource.getRepository(Assign) - private assignOutputRepository = AppDataSource.getRepository(AssignOutput) - /** - * API สำหรับออกรายงาน - * - * @summary ผลการทดลองปฏิบัติราชการ - * - */ - @Get("") - async GetReport(@Query() assign_id: string, @Query() evaluate_no: number = 1) { - const evaluate = await this.evaluateChairmanRepository.findOne({ - where: { assign_id, no: evaluate_no.toString() }, - }) - - const result = await this.evaluateResultRepository.findOne({ - where: { assign_id, no: evaluate_no.toString() }, - }) - - if (!evaluate || !result) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลการทดลองปฏิบัติราชการ") - } - - const develop_total_score = - (await (Number(evaluate.develop_orientation_score) + - Number(evaluate.develop_self_learning_score) + - Number(evaluate.develop_training_seminar_score) + - Number(evaluate.develop_other_training_score))) / 4 - const develop_total_percent = - (await (Number(evaluate.develop_orientation_percent) + - Number(evaluate.develop_self_learning_percent) + - Number(evaluate.develop_training_seminar_percent) + - Number(evaluate.develop_other_training_percent))) / 4 - - const data = await { - develop_orientation_score: evaluate.develop_orientation_score, - develop_self_learning_score: evaluate.develop_self_learning_score, - develop_training_seminar_score: evaluate.develop_training_seminar_score, - develop_other_training_score: evaluate.develop_other_training_score, - develop_total_score, - develop_orientation_percent: evaluate.develop_orientation_percent, - develop_self_learning_percent: evaluate.develop_self_learning_percent, - develop_training_seminar_percent: evaluate.develop_training_seminar_percent, - develop_other_training_percent: evaluate.develop_other_training_percent, - develop_total_percent, - develop_result: evaluate.develop_result, - achievement_score: evaluate.achievement_score, - achievement_score_total: evaluate.achievement_score_total, - achievement_percent: evaluate.achievement_percent, - achievement_result: evaluate.achievement_result, - behavior_score: evaluate.behavior_score, - behavior_score_total: evaluate.behavior_score_total, - behavior_percent: evaluate.behavior_percent, - behavior_result: evaluate.behavior_result, - sum_score: evaluate.sum_score, - sum_percent: evaluate.sum_percent, - reason: result.reson, - pass_result: result.pass_result, - evaluate_date: result.chairman_dated, - } - - return new HttpSuccess(data) - } - - /** - * API แสดงรายการผู้ผ่านทดลองงาน - * - * @summary รายการผู้ผ่านทดลองงาน - * - */ - @Get("pass") - async GetPass() { - const lists = await this.personalRepository.find({ - where: { probation_status: 2 }, - }) - - let data: DataPass[] = [] - await Promise.all( - lists.map(async list => { - const assign = await AppDataSource.getRepository(Assign).findOne({ - select: ["date_start", "date_finish"], - where: { personal_id: list.personal_id }, - }) - - if (assign) - data.push({ - person: { - id: list.personal_id, - name: `${list.prefixName}${list.firstName} ${list.lastName}`, - }, - assign, - }) - }) - ) - - return new HttpSuccess(data) - } - - /** - * API แสดงรายการผู้ไม่ผ่านทดลองงาน - * - * @summary รายการคนไม่ผ่านการทดลองปฏิบัติราชการและรอไปออกคำสั่ง - * - */ - @Get("not-pass") - async GetDataNotPass() { - const lists = await this.personalRepository.find({ - where: { probation_status: 3 }, - }) - - let data: DataPass[] = [] - await Promise.all( - lists.map(async list => { - const assign = await AppDataSource.getRepository(Assign).findOne({ - select: ["date_start", "date_finish"], - where: { personal_id: list.personal_id }, - }) - - if (assign) - data.push({ - person: { - id: list.personal_id, - name: `${list.prefixName}${list.firstName} ${list.lastName}`, - }, - assign, - }) - }) - ) - - return new HttpSuccess(data) - } - - /** - * API แสดงรายการคนที่ถูกขยายระยะเวลาทดลองงาน - * - * @summary รายการคนที่ถูกขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการและรอไปออกคำสั่ง - * - */ - @Get("expand") - async GetDataExpand() { - const data = await this.personalRepository.find({ - select: ["personal_id"], - where: { probation_status: 7 }, - }) - - return new HttpSuccess(data) - } - - /** - * API สำหรับปรับสถานะการดึงไปออกคำสั่ง - * - * @summary ปรับสถานะการดึงไปออกคำสั่ง - * - */ - @Put("status") - async UpdateStatus(@Query() personal_id: string, @Body() requestBody: { command_no: string }, @Request() request: RequestWithUser) { - const personal = await this.personalRepository.findOne({ - where: { personal_id }, - }) - const before = personal - - if (!personal) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล") - } - - personal.order_number = requestBody.command_no - personal.probation_status = 8 - personal.updateFullName = request.user.name - personal.updateUserId = request.user.sub - - this.personalRepository.save(personal, { data: request }) - setLogDataDiff(request, { before, after: personal }) - - const resultText = (await personal.probation_status) === 2 ? "ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้รับราชการต่อ" : "ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ออกจากราชการ" - - await new CallAPI() - .PostData(request, "/placement/noti", { - subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ", - body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ ${resultText}`, - receiverUserId: personal_id, - payload: "", - isSendMail: false, - isSendInbox: true, - isSendNotification: true, - }) - .catch(error => { - console.error("Error calling API:", error) - }) - - return new HttpSuccess() - } - - /** - * API สำหรับปรับสถานะการดึงไปออกคำสั่ง - * - * @summary ปรับสถานะการดึงไปออกคำสั่ง - * - */ - @Put("change-status") - async ChangeStatus(@Query() personal_id: string, @Body() reqBody: { status: number }, @Request() request: RequestWithUser) { - const personal = await this.personalRepository.findOne({ - where: { personal_id }, - }) - const before = personal - - if (!personal) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล") - } - - personal.probation_status = await reqBody.status - personal.updateFullName = request.user.name - personal.updateUserId = request.user.sub - - await this.personalRepository.save(personal, { data: request }) - setLogDataDiff(request, { before, after: personal }) - - return new HttpSuccess() - } - - /** - * API แสดงข้อมูลแบบบันทึกผลตาม id - * - * @summary ข้อมูลแบบบันทึกผลตาม id - * - */ - @Get("form-record") - async GetDataFormRecord(@Query() id: string) { - const evaluate = await this.evaluateAssessorRepository.findOne({ - where: { id }, - }) - - if (!evaluate) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const directorData = await this.assignDirectorRepository.findOne({ - select: ["personal_id", "fullname", "position", "posType", "posLevel", "role", "dated"], - where: { personal_id: evaluate.director_id }, - }) - - if (!directorData) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const director = await { - ...directorData, - name: directorData.fullname, - position: directorData.position + directorData.posLevel, - } - - const achievements = await this.evaluateAchievementRepository.find({ - select: ["evaluate_expect_level", "evaluate_output_level", "output_desc", "output_id", "assign_id"], - where: { evaluate_id: evaluate.id }, - order: { updatedAt: "ASC" }, - }) - - if (!achievements) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - let evaluate_expect_level: any = [] - let evaluate_output_level: any = [] - for (let index = 0; index < achievements.length; index++) { - const element = achievements[index] - - const outputData = await this.assignOutputRepository.findOne({ - select: ["output_desc"], - where: { id: Number(element.output_id), assign_id: element.assign_id }, - }) - await evaluate_expect_level.push({ - title: outputData?.output_desc ?? "-", - col1: element.evaluate_expect_level == 1 ? "/" : "", - col2: element.evaluate_expect_level == 2 ? "/" : "", - col3: element.evaluate_expect_level == 3 ? "/" : "", - col4: element.evaluate_expect_level == 4 ? "/" : "", - col5: element.evaluate_expect_level == 5 ? "/" : "", - }) - - await evaluate_output_level.push({ - title: element.output_desc, - col1: element.evaluate_output_level == 1 ? "/" : "", - col2: element.evaluate_output_level == 2 ? "/" : "", - col3: element.evaluate_output_level == 3 ? "/" : "", - col4: element.evaluate_output_level == 4 ? "/" : "", - col5: element.evaluate_output_level == 5 ? "/" : "", - }) - } - - let achievement = { - evaluate_expect_level: evaluate_expect_level, - evaluate_output_level: evaluate_output_level, - } - - const evaluateData = await { - id: evaluate.id, - no: evaluate.no, - date_start: evaluate.date_start, - date_finish: evaluate.date_finish, - sign_dated: evaluate.assessor_dated, - knowledge_level: { - col1: evaluate.knowledge_level == 1 ? "/" : "", - col2: evaluate.knowledge_level == 2 ? "/" : "", - col3: evaluate.knowledge_level == 3 ? "/" : "", - col4: evaluate.knowledge_level == 4 ? "/" : "", - col5: evaluate.knowledge_level == 5 ? "/" : "", - }, - skill_level: { - col1: evaluate.skill_level == 1 ? "/" : "", - col2: evaluate.skill_level == 2 ? "/" : "", - col3: evaluate.skill_level == 3 ? "/" : "", - col4: evaluate.skill_level == 4 ? "/" : "", - col5: evaluate.skill_level == 5 ? "/" : "", - }, - competency_level: { - col1: evaluate.competency_level == 1 ? "/" : "", - col2: evaluate.competency_level == 2 ? "/" : "", - col3: evaluate.competency_level == 3 ? "/" : "", - col4: evaluate.competency_level == 4 ? "/" : "", - col5: evaluate.competency_level == 5 ? "/" : "", - }, - learn_level: { - col1: evaluate.learn_level == 1 ? "/" : "", - col2: evaluate.learn_level == 2 ? "/" : "", - col3: evaluate.learn_level == 3 ? "/" : "", - col4: evaluate.learn_level == 4 ? "/" : "", - col5: evaluate.learn_level == 5 ? "/" : "", - }, - apply_level: { - col1: evaluate.apply_level == 1 ? "/" : "", - col2: evaluate.apply_level == 2 ? "/" : "", - col3: evaluate.apply_level == 3 ? "/" : "", - col4: evaluate.apply_level == 4 ? "/" : "", - col5: evaluate.apply_level == 5 ? "/" : "", - }, - achievement_other_desc: evaluate.achievement_other_desc, - achievement_other_level: - evaluate.achievement_other_level != null - ? { - col1: evaluate.achievement_other_level == 1 ? "/" : "", - col2: evaluate.achievement_other_level == 2 ? "/" : "", - col3: evaluate.achievement_other_level == 3 ? "/" : "", - col4: evaluate.achievement_other_level == 4 ? "/" : "", - col5: evaluate.achievement_other_level == 5 ? "/" : "", - } - : { - col1: "", - col2: "", - col3: "", - col4: "", - col5: "", - }, - achievement_strength_desc: evaluate.achievement_strength_desc, - achievement_improve_desc: evaluate.achievement_improve_desc, - conduct1_level: { - col1: evaluate.conduct1_level == 1 ? "/" : "", - col2: evaluate.conduct1_level == 2 ? "/" : "", - col3: evaluate.conduct1_level == 3 ? "/" : "", - col4: evaluate.conduct1_level == 4 ? "/" : "", - col5: evaluate.conduct1_level == 5 ? "/" : "", - }, - conduct2_level: { - col1: evaluate.conduct2_level == 1 ? "/" : "", - col2: evaluate.conduct2_level == 2 ? "/" : "", - col3: evaluate.conduct2_level == 3 ? "/" : "", - col4: evaluate.conduct2_level == 4 ? "/" : "", - col5: evaluate.conduct2_level == 5 ? "/" : "", - }, - conduct3_level: { - col1: evaluate.conduct3_level == 1 ? "/" : "", - col2: evaluate.conduct3_level == 2 ? "/" : "", - col3: evaluate.conduct3_level == 3 ? "/" : "", - col4: evaluate.conduct3_level == 4 ? "/" : "", - col5: evaluate.conduct3_level == 5 ? "/" : "", - }, - conduct4_level: { - col1: evaluate.conduct4_level == 1 ? "/" : "", - col2: evaluate.conduct4_level == 2 ? "/" : "", - col3: evaluate.conduct4_level == 3 ? "/" : "", - col4: evaluate.conduct4_level == 4 ? "/" : "", - col5: evaluate.conduct4_level == 5 ? "/" : "", - }, - moral1_level: { - col1: evaluate.moral1_level == 1 ? "/" : "", - col2: evaluate.moral1_level == 2 ? "/" : "", - col3: evaluate.moral1_level == 3 ? "/" : "", - col4: evaluate.moral1_level == 4 ? "/" : "", - col5: evaluate.moral1_level == 5 ? "/" : "", - }, - moral2_level: { - col1: evaluate.moral2_level == 1 ? "/" : "", - col2: evaluate.moral2_level == 2 ? "/" : "", - col3: evaluate.moral2_level == 3 ? "/" : "", - col4: evaluate.moral2_level == 4 ? "/" : "", - col5: evaluate.moral2_level == 5 ? "/" : "", - }, - moral3_level: { - col1: evaluate.moral3_level == 1 ? "/" : "", - col2: evaluate.moral3_level == 2 ? "/" : "", - col3: evaluate.moral3_level == 3 ? "/" : "", - col4: evaluate.moral3_level == 4 ? "/" : "", - col5: evaluate.moral3_level == 5 ? "/" : "", - }, - discipline1_level: { - col1: evaluate.discipline1_level == 1 ? "/" : "", - col2: evaluate.discipline1_level == 2 ? "/" : "", - col3: evaluate.discipline1_level == 3 ? "/" : "", - col4: evaluate.discipline1_level == 4 ? "/" : "", - col5: evaluate.discipline1_level == 5 ? "/" : "", - }, - discipline2_level: { - col1: evaluate.discipline2_level == 1 ? "/" : "", - col2: evaluate.discipline2_level == 2 ? "/" : "", - col3: evaluate.discipline2_level == 3 ? "/" : "", - col4: evaluate.discipline2_level == 4 ? "/" : "", - col5: evaluate.discipline2_level == 5 ? "/" : "", - }, - discipline3_level: { - col1: evaluate.discipline3_level == 1 ? "/" : "", - col2: evaluate.discipline3_level == 2 ? "/" : "", - col3: evaluate.discipline3_level == 3 ? "/" : "", - col4: evaluate.discipline3_level == 4 ? "/" : "", - col5: evaluate.discipline3_level == 5 ? "/" : "", - }, - discipline4_level: { - col1: evaluate.discipline4_level == 1 ? "/" : "", - col2: evaluate.discipline4_level == 2 ? "/" : "", - col3: evaluate.discipline4_level == 3 ? "/" : "", - col4: evaluate.discipline4_level == 4 ? "/" : "", - col5: evaluate.discipline4_level == 5 ? "/" : "", - }, - discipline5_level: { - col1: evaluate.discipline5_level == 1 ? "/" : "", - col2: evaluate.discipline5_level == 2 ? "/" : "", - col3: evaluate.discipline5_level == 3 ? "/" : "", - col4: evaluate.discipline5_level == 4 ? "/" : "", - col5: evaluate.discipline5_level == 5 ? "/" : "", - }, - behavior_other_desc: evaluate.behavior_other_desc, - behavior_other_level: - evaluate.behavior_other_level != null - ? { - col1: evaluate.behavior_other_level == 1 ? "/" : "", - col2: evaluate.behavior_other_level == 2 ? "/" : "", - col3: evaluate.behavior_other_level == 3 ? "/" : "", - col4: evaluate.behavior_other_level == 4 ? "/" : "", - col5: evaluate.behavior_other_level == 5 ? "/" : "", - } - : { - col1: "", - col2: "", - col3: "", - col4: "", - col5: "", - }, - - behavior_strength_desc: evaluate.behavior_strength_desc, - behavior_improve_desc: evaluate.behavior_improve_desc, - orientation: evaluate.orientation, - self_learning: evaluate.self_learning, - training_seminar: evaluate.training_seminar, - other_training: evaluate.other_training, - createdAt: evaluate.createdAt, - updatedAt: evaluate.updatedAt, - achievements: achievement, - role: director.role, - } - - const assign = await AppDataSource.getRepository(Assign).findOne({ - select: ["id", "personal_id", "round_no", "date_start", "date_finish"], - where: { id: evaluate.assign_id }, - }) - - if (!assign) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const experimenteeData = await this.personalRepository.findOne({ - where: { - personal_id: assign.personal_id, - }, - }) - - if (!experimenteeData) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const splitOc = await experimenteeData.organization.split(" ") - const splitOcAmount = await splitOc.length - const organization = await experimenteeData.organization.replace(/\//g, " ") - - const experimentee = await { - ...experimenteeData, - organization: organization, - name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, - PositionLevelName: experimenteeData.positionLevelName, - PositionLineName: experimenteeData.positionLineName, - Position: experimenteeData.positionName, - Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-", - OrganizationOrganization: splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-", - Oc: experimenteeData.orgRootName, - PositionLevel: experimenteeData.positionName + experimenteeData.positionLevelName, - } - - const data = await { - experimentee: experimentee ? experimentee : null, - director: director ? director : null, - assign, - evaluate: evaluateData, - } - return new HttpSuccess(data) - } - - /** - * API แสดงข้อมูลแบบประเมินผล (ผู้บังคับบัญชา) ตาม id - * - * @summary ข้อมูลแบบประเมินผล (ผู้บังคับบัญชา) ตาม id - * - */ - @Get("evaluate-commander") - async GetDataEvaluateCommander(@Query() id: string, @Request() request: RequestWithUser) { - const evaluate = await this.evaluateCommanderRepository.findOne({ - where: { id }, - }) - - if (!evaluate) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const evaluateData = await { - id: evaluate.id, - no: evaluate.no, - date_start: evaluate.date_start, - date_finish: evaluate.date_finish, - sign_dated: evaluate.commander_dated, - knowledge_level: { - col1: evaluate.knowledge_level == 1 ? "/" : "", - col2: evaluate.knowledge_level == 2 ? "/" : "", - col3: evaluate.knowledge_level == 3 ? "/" : "", - col4: evaluate.knowledge_level == 4 ? "/" : "", - col5: evaluate.knowledge_level == 5 ? "/" : "", - }, - skill_level: { - col1: evaluate.skill_level == 1 ? "/" : "", - col2: evaluate.skill_level == 2 ? "/" : "", - col3: evaluate.skill_level == 3 ? "/" : "", - col4: evaluate.skill_level == 4 ? "/" : "", - col5: evaluate.skill_level == 5 ? "/" : "", - }, - competency_level: { - col1: evaluate.competency_level == 1 ? "/" : "", - col2: evaluate.competency_level == 2 ? "/" : "", - col3: evaluate.competency_level == 3 ? "/" : "", - col4: evaluate.competency_level == 4 ? "/" : "", - col5: evaluate.competency_level == 5 ? "/" : "", - }, - learn_level: { - col1: evaluate.learn_level == 1 ? "/" : "", - col2: evaluate.learn_level == 2 ? "/" : "", - col3: evaluate.learn_level == 3 ? "/" : "", - col4: evaluate.learn_level == 4 ? "/" : "", - col5: evaluate.learn_level == 5 ? "/" : "", - }, - apply_level: { - col1: evaluate.apply_level == 1 ? "/" : "", - col2: evaluate.apply_level == 2 ? "/" : "", - col3: evaluate.apply_level == 3 ? "/" : "", - col4: evaluate.apply_level == 4 ? "/" : "", - col5: evaluate.apply_level == 5 ? "/" : "", - }, - success_level: { - col1: evaluate.success_level == 1 ? "/" : "", - col2: evaluate.success_level == 2 ? "/" : "", - col3: evaluate.success_level == 3 ? "/" : "", - col4: evaluate.success_level == 4 ? "/" : "", - col5: evaluate.success_level == 5 ? "/" : "", - }, - achievement_other_desc: evaluate.achievement_other_desc, - achievement_other_level: - evaluate.achievement_other_level != null - ? { - col1: evaluate.achievement_other_level == 1 ? "/" : "", - col2: evaluate.achievement_other_level == 2 ? "/" : "", - col3: evaluate.achievement_other_level == 3 ? "/" : "", - col4: evaluate.achievement_other_level == 4 ? "/" : "", - col5: evaluate.achievement_other_level == 5 ? "/" : "", - } - : { - col1: "", - col2: "", - col3: "", - col4: "", - col5: "", - }, - conduct1_level: { - col1: evaluate.conduct1_level == 1 ? "/" : "", - col2: evaluate.conduct1_level == 2 ? "/" : "", - col3: evaluate.conduct1_level == 3 ? "/" : "", - col4: evaluate.conduct1_level == 4 ? "/" : "", - col5: evaluate.conduct1_level == 5 ? "/" : "", - }, - conduct2_level: { - col1: evaluate.conduct2_level == 1 ? "/" : "", - col2: evaluate.conduct2_level == 2 ? "/" : "", - col3: evaluate.conduct2_level == 3 ? "/" : "", - col4: evaluate.conduct2_level == 4 ? "/" : "", - col5: evaluate.conduct2_level == 5 ? "/" : "", - }, - conduct3_level: { - col1: evaluate.conduct3_level == 1 ? "/" : "", - col2: evaluate.conduct3_level == 2 ? "/" : "", - col3: evaluate.conduct3_level == 3 ? "/" : "", - col4: evaluate.conduct3_level == 4 ? "/" : "", - col5: evaluate.conduct3_level == 5 ? "/" : "", - }, - conduct4_level: { - col1: evaluate.conduct4_level == 1 ? "/" : "", - col2: evaluate.conduct4_level == 2 ? "/" : "", - col3: evaluate.conduct4_level == 3 ? "/" : "", - col4: evaluate.conduct4_level == 4 ? "/" : "", - col5: evaluate.conduct4_level == 5 ? "/" : "", - }, - moral1_level: { - col1: evaluate.moral1_level == 1 ? "/" : "", - col2: evaluate.moral1_level == 2 ? "/" : "", - col3: evaluate.moral1_level == 3 ? "/" : "", - col4: evaluate.moral1_level == 4 ? "/" : "", - col5: evaluate.moral1_level == 5 ? "/" : "", - }, - moral2_level: { - col1: evaluate.moral2_level == 1 ? "/" : "", - col2: evaluate.moral2_level == 2 ? "/" : "", - col3: evaluate.moral2_level == 3 ? "/" : "", - col4: evaluate.moral2_level == 4 ? "/" : "", - col5: evaluate.moral2_level == 5 ? "/" : "", - }, - moral3_level: { - col1: evaluate.moral3_level == 1 ? "/" : "", - col2: evaluate.moral3_level == 2 ? "/" : "", - col3: evaluate.moral3_level == 3 ? "/" : "", - col4: evaluate.moral3_level == 4 ? "/" : "", - col5: evaluate.moral3_level == 5 ? "/" : "", - }, - discipline1_level: { - col1: evaluate.discipline1_level == 1 ? "/" : "", - col2: evaluate.discipline1_level == 2 ? "/" : "", - col3: evaluate.discipline1_level == 3 ? "/" : "", - col4: evaluate.discipline1_level == 4 ? "/" : "", - col5: evaluate.discipline1_level == 5 ? "/" : "", - }, - discipline2_level: { - col1: evaluate.discipline2_level == 1 ? "/" : "", - col2: evaluate.discipline2_level == 2 ? "/" : "", - col3: evaluate.discipline2_level == 3 ? "/" : "", - col4: evaluate.discipline2_level == 4 ? "/" : "", - col5: evaluate.discipline2_level == 5 ? "/" : "", - }, - discipline3_level: { - col1: evaluate.discipline3_level == 1 ? "/" : "", - col2: evaluate.discipline3_level == 2 ? "/" : "", - col3: evaluate.discipline3_level == 3 ? "/" : "", - col4: evaluate.discipline3_level == 4 ? "/" : "", - col5: evaluate.discipline3_level == 5 ? "/" : "", - }, - discipline4_level: { - col1: evaluate.discipline4_level == 1 ? "/" : "", - col2: evaluate.discipline4_level == 2 ? "/" : "", - col3: evaluate.discipline4_level == 3 ? "/" : "", - col4: evaluate.discipline4_level == 4 ? "/" : "", - col5: evaluate.discipline4_level == 5 ? "/" : "", - }, - discipline5_level: { - col1: evaluate.discipline5_level == 1 ? "/" : "", - col2: evaluate.discipline5_level == 2 ? "/" : "", - col3: evaluate.discipline5_level == 3 ? "/" : "", - col4: evaluate.discipline5_level == 4 ? "/" : "", - col5: evaluate.discipline5_level == 5 ? "/" : "", - }, - behavior_other_desc: evaluate.behavior_other_desc, - behavior_other_level: - evaluate.behavior_other_level != null - ? { - col1: evaluate.behavior_other_level == 1 ? "/" : "", - col2: evaluate.behavior_other_level == 2 ? "/" : "", - col3: evaluate.behavior_other_level == 3 ? "/" : "", - col4: evaluate.behavior_other_level == 4 ? "/" : "", - col5: evaluate.behavior_other_level == 5 ? "/" : "", - } - : { - col1: "", - col2: "", - col3: "", - col4: "", - col5: "", - }, - behavior_strength_desc: evaluate.behavior_strength_desc, - behavior_improve_desc: evaluate.behavior_improve_desc, - orientation: evaluate.orientation, - self_learning: evaluate.self_learning, - training_seminar: evaluate.training_seminar, - other_training: evaluate.other_training, - createdAt: evaluate.createdAt, - updatedAt: evaluate.updatedAt, - } - - const assign = await AppDataSource.getRepository(Assign).findOne({ - select: ["id", "personal_id", "round_no", "date_start", "date_finish"], - where: { id: evaluate.assign_id }, - }) - - if (!assign) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const experimenteeData = await this.personalRepository.findOne({ - where: { - personal_id: assign.personal_id, - }, - }) - - if (!experimenteeData) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const splitOc = await experimenteeData.organization.split(" ") - const splitOcAmount = await splitOc.length - const organization = await experimenteeData.organization.replace(/\//g, " ") - - const experimentee = await { - ...experimenteeData, - organization: organization, - name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, - PositionLevelName: experimenteeData.positionLevelName, - PositionLineName: experimenteeData.positionLineName, - Position: experimenteeData.positionName, - Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-", - OrganizationOrganization: splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-", - Oc: experimenteeData.orgRootName, - PositionLevel: experimenteeData.positionName + experimenteeData.positionLevelName, - } - - const commanderData = await this.assignDirectorRepository.findOne({ - select: ["personal_id", "fullname", "position", "position", "posType", "posLevel", "role", "dated"], - where: { personal_id: evaluate.director_id }, - }) - - if (!commanderData) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const commander = await { - ...commanderData, - name: commanderData.fullname, - Position: commanderData.position + commanderData.posLevel, - } - - return new HttpSuccess({ - experimentee: experimentee ? experimentee : null, - commander: commander ? commander : null, - assign, - evaluate: evaluateData, - }) - } - - /** - * API แสดงข้อมูลแบบประเมินผล (คณะกรรมการ) ตาม id - * - * @summary ข้อมูลแบบประเมินผล (คณะกรรมการ) ตาม id - * - */ - @Get("evaluate-chairman") - async GetDataEvaluateChairman(@Query() id: string, @Request() request: RequestWithUser) { - const evaluate = await this.evaluateChairmanRepository.findOne({ - where: { id }, - }) - - if (!evaluate) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const develop_total_score = await (Number(evaluate.develop_orientation_score) + - Number(evaluate.develop_self_learning_score) + - Number(evaluate.develop_training_seminar_score) + - Number(evaluate.develop_other_training_score)) - const develop_total_percent = await (Number(evaluate.develop_orientation_percent) + - Number(evaluate.develop_orientation_percent) + - Number(evaluate.develop_self_learning_percent) + - Number(evaluate.develop_training_seminar_percent)) - - const evaluateData = await { - id: evaluate.id, - // director_id: evaluate.director_id, - // assign_id: evaluate.assign_id, - no: evaluate.no, - date_start: evaluate.date_start, - date_finish: evaluate.date_finish, - chairman_dated: evaluate.chairman_dated, - director1_dated: evaluate.director1_dated, - director2_dated: evaluate.director2_dated, - knowledge_level: { - col1: evaluate.knowledge_level == 1 ? "/" : "", - col2: evaluate.knowledge_level == 2 ? "/" : "", - col3: evaluate.knowledge_level == 3 ? "/" : "", - col4: evaluate.knowledge_level == 4 ? "/" : "", - col5: evaluate.knowledge_level == 5 ? "/" : "", - }, - apply_level: { - col1: evaluate.apply_level == 1 ? "/" : "", - col2: evaluate.apply_level == 2 ? "/" : "", - col3: evaluate.apply_level == 3 ? "/" : "", - col4: evaluate.apply_level == 4 ? "/" : "", - col5: evaluate.apply_level == 5 ? "/" : "", - }, - success_level: { - col1: evaluate.success_level == 1 ? "/" : "", - col2: evaluate.success_level == 2 ? "/" : "", - col3: evaluate.success_level == 3 ? "/" : "", - col4: evaluate.success_level == 4 ? "/" : "", - col5: evaluate.success_level == 5 ? "/" : "", - }, - achievement_other_desc: evaluate.achievement_other_desc, - achievement_other_level: - evaluate.achievement_other_level != null - ? { - col1: evaluate.achievement_other_level == 1 ? "/" : "", - col2: evaluate.achievement_other_level == 2 ? "/" : "", - col3: evaluate.achievement_other_level == 3 ? "/" : "", - col4: evaluate.achievement_other_level == 4 ? "/" : "", - col5: evaluate.achievement_other_level == 5 ? "/" : "", - } - : { - col1: "", - col2: "", - col3: "", - col4: "", - col5: "", - }, - conduct1_level: { - col1: evaluate.conduct1_level == 1 ? "/" : "", - col2: evaluate.conduct1_level == 2 ? "/" : "", - col3: evaluate.conduct1_level == 3 ? "/" : "", - col4: evaluate.conduct1_level == 4 ? "/" : "", - col5: evaluate.conduct1_level == 5 ? "/" : "", - }, - conduct2_level: { - col1: evaluate.conduct2_level == 1 ? "/" : "", - col2: evaluate.conduct2_level == 2 ? "/" : "", - col3: evaluate.conduct2_level == 3 ? "/" : "", - col4: evaluate.conduct2_level == 4 ? "/" : "", - col5: evaluate.conduct2_level == 5 ? "/" : "", - }, - conduct3_level: { - col1: evaluate.conduct3_level == 1 ? "/" : "", - col2: evaluate.conduct3_level == 2 ? "/" : "", - col3: evaluate.conduct3_level == 3 ? "/" : "", - col4: evaluate.conduct3_level == 4 ? "/" : "", - col5: evaluate.conduct3_level == 5 ? "/" : "", - }, - conduct4_level: { - col1: evaluate.conduct4_level == 1 ? "/" : "", - col2: evaluate.conduct4_level == 2 ? "/" : "", - col3: evaluate.conduct4_level == 3 ? "/" : "", - col4: evaluate.conduct4_level == 4 ? "/" : "", - col5: evaluate.conduct4_level == 5 ? "/" : "", - }, - moral1_level: { - col1: evaluate.moral1_level == 1 ? "/" : "", - col2: evaluate.moral1_level == 2 ? "/" : "", - col3: evaluate.moral1_level == 3 ? "/" : "", - col4: evaluate.moral1_level == 4 ? "/" : "", - col5: evaluate.moral1_level == 5 ? "/" : "", - }, - moral2_level: { - col1: evaluate.moral2_level == 1 ? "/" : "", - col2: evaluate.moral2_level == 2 ? "/" : "", - col3: evaluate.moral2_level == 3 ? "/" : "", - col4: evaluate.moral2_level == 4 ? "/" : "", - col5: evaluate.moral2_level == 5 ? "/" : "", - }, - moral3_level: { - col1: evaluate.moral3_level == 1 ? "/" : "", - col2: evaluate.moral3_level == 2 ? "/" : "", - col3: evaluate.moral3_level == 3 ? "/" : "", - col4: evaluate.moral3_level == 4 ? "/" : "", - col5: evaluate.moral3_level == 5 ? "/" : "", - }, - discipline1_level: { - col1: evaluate.discipline1_level == 1 ? "/" : "", - col2: evaluate.discipline1_level == 2 ? "/" : "", - col3: evaluate.discipline1_level == 3 ? "/" : "", - col4: evaluate.discipline1_level == 4 ? "/" : "", - col5: evaluate.discipline1_level == 5 ? "/" : "", - }, - discipline2_level: { - col1: evaluate.discipline2_level == 1 ? "/" : "", - col2: evaluate.discipline2_level == 2 ? "/" : "", - col3: evaluate.discipline2_level == 3 ? "/" : "", - col4: evaluate.discipline2_level == 4 ? "/" : "", - col5: evaluate.discipline2_level == 5 ? "/" : "", - }, - discipline3_level: { - col1: evaluate.discipline3_level == 1 ? "/" : "", - col2: evaluate.discipline3_level == 2 ? "/" : "", - col3: evaluate.discipline3_level == 3 ? "/" : "", - col4: evaluate.discipline3_level == 4 ? "/" : "", - col5: evaluate.discipline3_level == 5 ? "/" : "", - }, - discipline4_level: { - col1: evaluate.discipline4_level == 1 ? "/" : "", - col2: evaluate.discipline4_level == 2 ? "/" : "", - col3: evaluate.discipline4_level == 3 ? "/" : "", - col4: evaluate.discipline4_level == 4 ? "/" : "", - col5: evaluate.discipline4_level == 5 ? "/" : "", - }, - discipline5_level: { - col1: evaluate.discipline5_level == 1 ? "/" : "", - col2: evaluate.discipline5_level == 2 ? "/" : "", - col3: evaluate.discipline5_level == 3 ? "/" : "", - col4: evaluate.discipline5_level == 4 ? "/" : "", - col5: evaluate.discipline5_level == 5 ? "/" : "", - }, - behavior_other_desc: evaluate.behavior_other_desc, - behavior_other_level: - evaluate.behavior_other_level != null - ? { - col1: evaluate.behavior_other_level == 1 ? "/" : "", - col2: evaluate.behavior_other_level == 2 ? "/" : "", - col3: evaluate.behavior_other_level == 3 ? "/" : "", - col4: evaluate.behavior_other_level == 4 ? "/" : "", - col5: evaluate.behavior_other_level == 5 ? "/" : "", - } - : { - col1: "", - col2: "", - col3: "", - col4: "", - col5: "", - }, - - achievement_score: evaluate.achievement_score, - achievement_score_total: evaluate.achievement_score_total, - achievement_percent: evaluate.achievement_percent, - achievement_result: evaluate.achievement_result, - behavior_score: evaluate.behavior_score, - behavior_score_total: evaluate.behavior_score_total, - behavior_percent: evaluate.behavior_percent, - behavior_result: evaluate.behavior_result, - sum_score: evaluate.sum_score, - sum_percent: evaluate.sum_percent, - - develop_orientation_score: evaluate.develop_orientation_score, - develop_self_learning_score: evaluate.develop_self_learning_score, - develop_training_seminar_score: evaluate.develop_training_seminar_score, - develop_other_training_score: evaluate.develop_other_training_score, - develop_total_score: develop_total_score, - develop_orientation_percent: evaluate.develop_orientation_percent, - develop_self_learning_percent: evaluate.develop_self_learning_percent, - develop_training_seminar_percent: evaluate.develop_training_seminar_percent, - develop_other_training_percent: evaluate.develop_other_training_percent, - develop_total_percent: develop_total_percent, - develop_result: evaluate.develop_result, - evaluate_result: evaluate.evaluate_result, - createdAt: evaluate.createdAt, - updatedAt: evaluate.updatedAt, - } - - const assign = await AppDataSource.getRepository(Assign).findOne({ - select: ["id", "personal_id", "round_no", "date_start", "date_finish"], - where: { id: evaluate.assign_id }, - }) - - if (!assign) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const experimenteeData = await this.personalRepository.findOne({ - where: { - personal_id: assign.personal_id, - }, - }) - - if (!experimenteeData) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const splitOc = await experimenteeData.organization.split(" ") - const splitOcAmount = await splitOc.length - const organization = await experimenteeData.organization.replace(/\//g, " ") - - const experimentee = await { - ...experimenteeData, - organization: organization, - name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, - PositionLevelName: experimenteeData.positionLevelName, - PositionLineName: experimenteeData.positionLineName, - Position: experimenteeData.positionName, - Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-", - OrganizationOrganization: splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-", - Oc: experimenteeData.orgRootName, - PositionLevel: experimenteeData.positionName + experimenteeData.positionLevelName, - } - - const directorData = await this.assignDirectorRepository.find({ - select: ["personal_id", "fullname", "position", "posType", "posLevel", "role", "dated"], - where: { assign_id: assign.id }, - }) - - if (!directorData) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - const director = await Promise.all( - directorData.map(async element => { - return { - ...element, - name: element.fullname, - Position: element.position + element.posLevel, - } - }) - ) - - const mentorData = await (director.find(x => x.role == "mentor") ?? null) - const mentor = mentorData != null ? mentorData : null - - const commanderData = await (director.find(x => x.role == "commander") ?? null) - const commander = commanderData != null ? commanderData : null - - const chairmanData = await (director.find(x => x.role == "chairman") ?? null) - const chairman = chairmanData != null ? chairmanData : null - - return new HttpSuccess({ - experimentee: experimentee ? experimentee : null, - chairman: chairman ? chairman : null, - director1: commander ? commander : null, - director2: mentor ? mentor : null, - assign, - evaluate: evaluateData, - }) - } - - @Post("command11/officer/report/excecute") - public async command11Excecute( - @Request() request: RequestWithUser, - @Body() - body: { - refIds: { - refId: string - commandNo: string | null - commandYear: number | null - commandId: string | null - remark: string | null - amount: Double | null - amountSpecial?: Double | null - positionSalaryAmount: Double | null - mouthSalaryAmount: Double | null - commandCode?: string | null - commandName?: string | null - commandDateAffect: Date | null - commandDateSign: Date | null - }[] - } - ) { - await new CallAPI() - .PostData(request, "/org/command/excexute/salary-probation", { - data: body.refIds.map(v => ({ - profileId: v.refId, - commandId: v.commandId, - amount: v.amount, - amountSpecial: v.amountSpecial, - positionSalaryAmount: v.positionSalaryAmount, - mouthSalaryAmount: v.mouthSalaryAmount, - commandNo: v.commandNo, - commandYear: v.commandYear, - commandDateAffect: v.commandDateAffect, - commandDateSign: v.commandDateSign, - commandCode: v.commandCode, - commandName: v.commandName, - remark: v.remark, - })), - }) - .then(async res => { - const lists = await this.personalRepository.find({ - where: { probation_status: 8, personal_id: In(body.refIds.map(x => x.refId)) }, - }) - await Promise.all( - lists.map(async list => { - list.probation_status = 9 - await this.personalRepository.save(list) - }) - ) - }) - .catch(() => {}) - return new HttpSuccess() - } - @Post("command11/officer/report") - public async command11( - @Request() req: RequestWithUser, - @Body() - body: { - refIds: string[] - } - ) { - const lists = await this.personalRepository.find({ - where: { probation_status: 2, personal_id: In(body.refIds) }, - }) - await Promise.all( - lists.map(async list => { - list.probation_status = 8 - await this.personalRepository.save(list) - }) - ) - - return new HttpSuccess() - } - @Post("command11/officer/report/delete") - public async command11Delete( - @Request() req: RequestWithUser, - @Body() - body: { - refIds: string[] - } - ) { - const lists = await this.personalRepository.find({ - where: { probation_status: 8, personal_id: In(body.refIds) }, - }) - await Promise.all( - lists.map(async list => { - list.probation_status = 2 - await this.personalRepository.save(list) - }) - ) - - return new HttpSuccess() - } - - @Post("command12/officer/report/excecute") - public async command12Excecute( - @Request() request: RequestWithUser, - @Body() - body: { - refIds: { - refId: string - commandNo: string | null - commandYear: number | null - commandId: string | null - remark: string | null - amount: Double | null - amountSpecial?: Double | null - positionSalaryAmount: Double | null - mouthSalaryAmount: Double | null - commandCode?: string | null - commandName?: string | null - commandDateAffect: Date | null - commandDateSign: Date | null - }[] - } - ) { - await new CallAPI() - .PostData(request, "/org/command/excexute/salary-probation-leave", { - data: body.refIds.map(v => ({ - profileId: v.refId, - commandId: v.commandId, - amount: v.amount, - amountSpecial: v.amountSpecial, - positionSalaryAmount: v.positionSalaryAmount, - mouthSalaryAmount: v.mouthSalaryAmount, - isGovernment: false, - commandNo: v.commandNo, - commandYear: v.commandYear, - commandDateAffect: v.commandDateAffect, - commandDateSign: v.commandDateSign, - commandCode: v.commandCode, - commandName: v.commandName, - remark: v.remark, - })), - }) - .then(async res => { - const lists = await this.personalRepository.find({ - where: { probation_status: 8, personal_id: In(body.refIds.map(x => x.refId)) }, - }) - await Promise.all( - lists.map(async list => { - list.probation_status = 9 - await this.personalRepository.save(list) - }) - ) - }) - .catch(() => {}) - return new HttpSuccess() - } - @Post("command12/officer/report") - public async command12( - @Request() req: RequestWithUser, - @Body() - body: { - refIds: string[] - } - ) { - const lists = await this.personalRepository.find({ - where: { probation_status: 3, personal_id: In(body.refIds) }, - }) - await Promise.all( - lists.map(async list => { - list.probation_status = 8 - await this.personalRepository.save(list) - }) - ) - return new HttpSuccess() - } - @Post("command12/officer/report/delete") - public async command12Delete( - @Request() req: RequestWithUser, - @Body() - body: { - refIds: string[] - } - ) { - const lists = await this.personalRepository.find({ - where: { probation_status: 8, personal_id: In(body.refIds) }, - }) - await Promise.all( - lists.map(async list => { - list.probation_status = 3 - await this.personalRepository.save(list) - }) - ) - return new HttpSuccess() - } - - @Post("command10/officer/report/excecute") - public async command10Excecute( - @Request() request: RequestWithUser, - @Body() - body: { - refIds: { - refId: string - // commandAffectDate: Date | null //เก่า - commandDateAffect: Date | null //ใหม่ปรับตาม RabbitMQ ORG - commandDateSign?: Date | null - commandNo: string | null - commandId?: string | null - commandYear: number + private evaluateChairmanRepository = + AppDataSource.getRepository(EvaluateChairman); + private evaluateResultRepository = + AppDataSource.getRepository(EvaluateResult); + private personalRepository = AppDataSource.getRepository(Personal); + private evaluateAssessorRepository = + AppDataSource.getRepository(EvaluateAssessor); + private assignDirectorRepository = + AppDataSource.getRepository(AssignDirector); + private evaluateAchievementRepository = + AppDataSource.getRepository(EvaluateAchievement); + private evaluateCommanderRepository = + AppDataSource.getRepository(EvaluateCommander); + private appointRepository = AppDataSource.getRepository(Appoint); + private AppointDirectorRepository = + AppDataSource.getRepository(AppointDirector); + private assignRepository = AppDataSource.getRepository(Assign); + private assignOutputRepository = AppDataSource.getRepository(AssignOutput); + /** + * API สำหรับออกรายงาน + * + * @summary ผลการทดลองปฏิบัติราชการ + * + */ + @Get("") + async GetReport( + @Query() assign_id: string, + @Query() evaluate_no: number = 1 + ) { + const evaluate = await this.evaluateChairmanRepository.findOne({ + where: { assign_id, no: evaluate_no.toString() }, + }); + + const result = await this.evaluateResultRepository.findOne({ + where: { assign_id, no: evaluate_no.toString() }, + }); + + if (!evaluate || !result) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลผลการทดลองปฏิบัติราชการ" + ); + } + + const develop_total_score = + (await (Number(evaluate.develop_orientation_score) + + Number(evaluate.develop_self_learning_score) + + Number(evaluate.develop_training_seminar_score) + + Number(evaluate.develop_other_training_score))) / 4; + const develop_total_percent = + (await (Number(evaluate.develop_orientation_percent) + + Number(evaluate.develop_self_learning_percent) + + Number(evaluate.develop_training_seminar_percent) + + Number(evaluate.develop_other_training_percent))) / 4; + + const data = await { + develop_orientation_score: evaluate.develop_orientation_score, + develop_self_learning_score: evaluate.develop_self_learning_score, + develop_training_seminar_score: evaluate.develop_training_seminar_score, + develop_other_training_score: evaluate.develop_other_training_score, + develop_total_score, + develop_orientation_percent: evaluate.develop_orientation_percent, + develop_self_learning_percent: evaluate.develop_self_learning_percent, + develop_training_seminar_percent: + evaluate.develop_training_seminar_percent, + develop_other_training_percent: evaluate.develop_other_training_percent, + develop_total_percent, + develop_result: evaluate.develop_result, + achievement_score: evaluate.achievement_score, + achievement_score_total: evaluate.achievement_score_total, + achievement_percent: evaluate.achievement_percent, + achievement_result: evaluate.achievement_result, + behavior_score: evaluate.behavior_score, + behavior_score_total: evaluate.behavior_score_total, + behavior_percent: evaluate.behavior_percent, + behavior_result: evaluate.behavior_result, + sum_score: evaluate.sum_score, + sum_percent: evaluate.sum_percent, + reason: result.reson, + pass_result: result.pass_result, + evaluate_date: result.chairman_dated, + }; + + return new HttpSuccess(data); + } + + /** + * API แสดงรายการผู้ผ่านทดลองงาน + * + * @summary รายการผู้ผ่านทดลองงาน + * + */ + @Get("pass") + async GetPass() { + const lists = await this.personalRepository.find({ + where: { probation_status: 2 }, + }); + + let data: DataPass[] = []; + await Promise.all( + lists.map(async (list) => { + const assign = await AppDataSource.getRepository(Assign).findOne({ + select: ["date_start", "date_finish"], + where: { personal_id: list.personal_id }, + }); + + if (assign) + data.push({ + person: { + id: list.personal_id, + name: `${list.prefixName}${list.firstName} ${list.lastName}`, + }, + assign, + }); + }) + ); + + return new HttpSuccess(data); + } + + /** + * API แสดงรายการผู้ไม่ผ่านทดลองงาน + * + * @summary รายการคนไม่ผ่านการทดลองปฏิบัติราชการและรอไปออกคำสั่ง + * + */ + @Get("not-pass") + async GetDataNotPass() { + const lists = await this.personalRepository.find({ + where: { probation_status: 3 }, + }); + + let data: DataPass[] = []; + await Promise.all( + lists.map(async (list) => { + const assign = await AppDataSource.getRepository(Assign).findOne({ + select: ["date_start", "date_finish"], + where: { personal_id: list.personal_id }, + }); + + if (assign) + data.push({ + person: { + id: list.personal_id, + name: `${list.prefixName}${list.firstName} ${list.lastName}`, + }, + assign, + }); + }) + ); + + return new HttpSuccess(data); + } + + /** + * API แสดงรายการคนที่ถูกขยายระยะเวลาทดลองงาน + * + * @summary รายการคนที่ถูกขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการและรอไปออกคำสั่ง + * + */ + + @Get("expand") + async GetDataExpand() { + const data = await this.personalRepository.find({ + select: ["personal_id"], + where: { probation_status: 7 }, + }); + + // ✅ ส่งข้อมูลไปยังทุกไคลเอนต์ที่เชื่อมต่อ WebSocket + wss.clients.forEach((client) => { + if (client.readyState === WebSocket.OPEN) { + if (client.readyState === 1) { + client.send(JSON.stringify({ name: "test" })); + } + } + }); + + // return new HttpSuccess(data); + } + + /** + * API สำหรับปรับสถานะการดึงไปออกคำสั่ง + * + * @summary ปรับสถานะการดึงไปออกคำสั่ง + * + */ + @Put("status") + async UpdateStatus( + @Query() personal_id: string, + @Body() requestBody: { command_no: string }, + @Request() request: RequestWithUser + ) { + const personal = await this.personalRepository.findOne({ + where: { personal_id }, + }); + const before = personal; + + if (!personal) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล"); + } + + personal.order_number = requestBody.command_no; + personal.probation_status = 8; + personal.updateFullName = request.user.name; + personal.updateUserId = request.user.sub; + + this.personalRepository.save(personal, { data: request }); + setLogDataDiff(request, { before, after: personal }); + + const resultText = + (await personal.probation_status) === 2 + ? "ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้รับราชการต่อ" + : "ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ออกจากราชการ"; + + await new CallAPI() + .PostData(request, "/placement/noti", { + subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ", + body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ ${resultText}`, + receiverUserId: personal_id, + payload: "", + isSendMail: false, + isSendInbox: true, + isSendNotification: true, + }) + .catch((error) => { + console.error("Error calling API:", error); + }); + + return new HttpSuccess(); + } + + /** + * API สำหรับปรับสถานะการดึงไปออกคำสั่ง + * + * @summary ปรับสถานะการดึงไปออกคำสั่ง + * + */ + @Put("change-status") + async ChangeStatus( + @Query() personal_id: string, + @Body() reqBody: { status: number }, + @Request() request: RequestWithUser + ) { + const personal = await this.personalRepository.findOne({ + where: { personal_id }, + }); + const before = personal; + + if (!personal) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล"); + } + + personal.probation_status = await reqBody.status; + personal.updateFullName = request.user.name; + personal.updateUserId = request.user.sub; + + await this.personalRepository.save(personal, { data: request }); + setLogDataDiff(request, { before, after: personal }); + + return new HttpSuccess(); + } + + /** + * API แสดงข้อมูลแบบบันทึกผลตาม id + * + * @summary ข้อมูลแบบบันทึกผลตาม id + * + */ + @Get("form-record") + async GetDataFormRecord(@Query() id: string) { + const evaluate = await this.evaluateAssessorRepository.findOne({ + where: { id }, + }); + + if (!evaluate) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const directorData = await this.assignDirectorRepository.findOne({ + select: [ + "personal_id", + "fullname", + "position", + "posType", + "posLevel", + "role", + "dated", + ], + where: { personal_id: evaluate.director_id }, + }); + + if (!directorData) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const director = await { + ...directorData, + name: directorData.fullname, + position: directorData.position + directorData.posLevel, + }; + + const achievements = await this.evaluateAchievementRepository.find({ + select: [ + "evaluate_expect_level", + "evaluate_output_level", + "output_desc", + "output_id", + "assign_id", + ], + where: { evaluate_id: evaluate.id }, + order: { updatedAt: "ASC" }, + }); + + if (!achievements) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + let evaluate_expect_level: any = []; + let evaluate_output_level: any = []; + for (let index = 0; index < achievements.length; index++) { + const element = achievements[index]; + + const outputData = await this.assignOutputRepository.findOne({ + select: ["output_desc"], + where: { id: Number(element.output_id), assign_id: element.assign_id }, + }); + await evaluate_expect_level.push({ + title: outputData?.output_desc ?? "-", + col1: element.evaluate_expect_level == 1 ? "/" : "", + col2: element.evaluate_expect_level == 2 ? "/" : "", + col3: element.evaluate_expect_level == 3 ? "/" : "", + col4: element.evaluate_expect_level == 4 ? "/" : "", + col5: element.evaluate_expect_level == 5 ? "/" : "", + }); + + await evaluate_output_level.push({ + title: element.output_desc, + col1: element.evaluate_output_level == 1 ? "/" : "", + col2: element.evaluate_output_level == 2 ? "/" : "", + col3: element.evaluate_output_level == 3 ? "/" : "", + col4: element.evaluate_output_level == 4 ? "/" : "", + col5: element.evaluate_output_level == 5 ? "/" : "", + }); + } + + let achievement = { + evaluate_expect_level: evaluate_expect_level, + evaluate_output_level: evaluate_output_level, + }; + + const evaluateData = await { + id: evaluate.id, + no: evaluate.no, + date_start: evaluate.date_start, + date_finish: evaluate.date_finish, + sign_dated: evaluate.assessor_dated, + knowledge_level: { + col1: evaluate.knowledge_level == 1 ? "/" : "", + col2: evaluate.knowledge_level == 2 ? "/" : "", + col3: evaluate.knowledge_level == 3 ? "/" : "", + col4: evaluate.knowledge_level == 4 ? "/" : "", + col5: evaluate.knowledge_level == 5 ? "/" : "", + }, + skill_level: { + col1: evaluate.skill_level == 1 ? "/" : "", + col2: evaluate.skill_level == 2 ? "/" : "", + col3: evaluate.skill_level == 3 ? "/" : "", + col4: evaluate.skill_level == 4 ? "/" : "", + col5: evaluate.skill_level == 5 ? "/" : "", + }, + competency_level: { + col1: evaluate.competency_level == 1 ? "/" : "", + col2: evaluate.competency_level == 2 ? "/" : "", + col3: evaluate.competency_level == 3 ? "/" : "", + col4: evaluate.competency_level == 4 ? "/" : "", + col5: evaluate.competency_level == 5 ? "/" : "", + }, + learn_level: { + col1: evaluate.learn_level == 1 ? "/" : "", + col2: evaluate.learn_level == 2 ? "/" : "", + col3: evaluate.learn_level == 3 ? "/" : "", + col4: evaluate.learn_level == 4 ? "/" : "", + col5: evaluate.learn_level == 5 ? "/" : "", + }, + apply_level: { + col1: evaluate.apply_level == 1 ? "/" : "", + col2: evaluate.apply_level == 2 ? "/" : "", + col3: evaluate.apply_level == 3 ? "/" : "", + col4: evaluate.apply_level == 4 ? "/" : "", + col5: evaluate.apply_level == 5 ? "/" : "", + }, + achievement_other_desc: evaluate.achievement_other_desc, + achievement_other_level: + evaluate.achievement_other_level != null + ? { + col1: evaluate.achievement_other_level == 1 ? "/" : "", + col2: evaluate.achievement_other_level == 2 ? "/" : "", + col3: evaluate.achievement_other_level == 3 ? "/" : "", + col4: evaluate.achievement_other_level == 4 ? "/" : "", + col5: evaluate.achievement_other_level == 5 ? "/" : "", + } + : { + col1: "", + col2: "", + col3: "", + col4: "", + col5: "", + }, + achievement_strength_desc: evaluate.achievement_strength_desc, + achievement_improve_desc: evaluate.achievement_improve_desc, + conduct1_level: { + col1: evaluate.conduct1_level == 1 ? "/" : "", + col2: evaluate.conduct1_level == 2 ? "/" : "", + col3: evaluate.conduct1_level == 3 ? "/" : "", + col4: evaluate.conduct1_level == 4 ? "/" : "", + col5: evaluate.conduct1_level == 5 ? "/" : "", + }, + conduct2_level: { + col1: evaluate.conduct2_level == 1 ? "/" : "", + col2: evaluate.conduct2_level == 2 ? "/" : "", + col3: evaluate.conduct2_level == 3 ? "/" : "", + col4: evaluate.conduct2_level == 4 ? "/" : "", + col5: evaluate.conduct2_level == 5 ? "/" : "", + }, + conduct3_level: { + col1: evaluate.conduct3_level == 1 ? "/" : "", + col2: evaluate.conduct3_level == 2 ? "/" : "", + col3: evaluate.conduct3_level == 3 ? "/" : "", + col4: evaluate.conduct3_level == 4 ? "/" : "", + col5: evaluate.conduct3_level == 5 ? "/" : "", + }, + conduct4_level: { + col1: evaluate.conduct4_level == 1 ? "/" : "", + col2: evaluate.conduct4_level == 2 ? "/" : "", + col3: evaluate.conduct4_level == 3 ? "/" : "", + col4: evaluate.conduct4_level == 4 ? "/" : "", + col5: evaluate.conduct4_level == 5 ? "/" : "", + }, + moral1_level: { + col1: evaluate.moral1_level == 1 ? "/" : "", + col2: evaluate.moral1_level == 2 ? "/" : "", + col3: evaluate.moral1_level == 3 ? "/" : "", + col4: evaluate.moral1_level == 4 ? "/" : "", + col5: evaluate.moral1_level == 5 ? "/" : "", + }, + moral2_level: { + col1: evaluate.moral2_level == 1 ? "/" : "", + col2: evaluate.moral2_level == 2 ? "/" : "", + col3: evaluate.moral2_level == 3 ? "/" : "", + col4: evaluate.moral2_level == 4 ? "/" : "", + col5: evaluate.moral2_level == 5 ? "/" : "", + }, + moral3_level: { + col1: evaluate.moral3_level == 1 ? "/" : "", + col2: evaluate.moral3_level == 2 ? "/" : "", + col3: evaluate.moral3_level == 3 ? "/" : "", + col4: evaluate.moral3_level == 4 ? "/" : "", + col5: evaluate.moral3_level == 5 ? "/" : "", + }, + discipline1_level: { + col1: evaluate.discipline1_level == 1 ? "/" : "", + col2: evaluate.discipline1_level == 2 ? "/" : "", + col3: evaluate.discipline1_level == 3 ? "/" : "", + col4: evaluate.discipline1_level == 4 ? "/" : "", + col5: evaluate.discipline1_level == 5 ? "/" : "", + }, + discipline2_level: { + col1: evaluate.discipline2_level == 1 ? "/" : "", + col2: evaluate.discipline2_level == 2 ? "/" : "", + col3: evaluate.discipline2_level == 3 ? "/" : "", + col4: evaluate.discipline2_level == 4 ? "/" : "", + col5: evaluate.discipline2_level == 5 ? "/" : "", + }, + discipline3_level: { + col1: evaluate.discipline3_level == 1 ? "/" : "", + col2: evaluate.discipline3_level == 2 ? "/" : "", + col3: evaluate.discipline3_level == 3 ? "/" : "", + col4: evaluate.discipline3_level == 4 ? "/" : "", + col5: evaluate.discipline3_level == 5 ? "/" : "", + }, + discipline4_level: { + col1: evaluate.discipline4_level == 1 ? "/" : "", + col2: evaluate.discipline4_level == 2 ? "/" : "", + col3: evaluate.discipline4_level == 3 ? "/" : "", + col4: evaluate.discipline4_level == 4 ? "/" : "", + col5: evaluate.discipline4_level == 5 ? "/" : "", + }, + discipline5_level: { + col1: evaluate.discipline5_level == 1 ? "/" : "", + col2: evaluate.discipline5_level == 2 ? "/" : "", + col3: evaluate.discipline5_level == 3 ? "/" : "", + col4: evaluate.discipline5_level == 4 ? "/" : "", + col5: evaluate.discipline5_level == 5 ? "/" : "", + }, + behavior_other_desc: evaluate.behavior_other_desc, + behavior_other_level: + evaluate.behavior_other_level != null + ? { + col1: evaluate.behavior_other_level == 1 ? "/" : "", + col2: evaluate.behavior_other_level == 2 ? "/" : "", + col3: evaluate.behavior_other_level == 3 ? "/" : "", + col4: evaluate.behavior_other_level == 4 ? "/" : "", + col5: evaluate.behavior_other_level == 5 ? "/" : "", + } + : { + col1: "", + col2: "", + col3: "", + col4: "", + col5: "", + }, + + behavior_strength_desc: evaluate.behavior_strength_desc, + behavior_improve_desc: evaluate.behavior_improve_desc, + orientation: evaluate.orientation, + self_learning: evaluate.self_learning, + training_seminar: evaluate.training_seminar, + other_training: evaluate.other_training, + createdAt: evaluate.createdAt, + updatedAt: evaluate.updatedAt, + achievements: achievement, + role: director.role, + }; + + const assign = await AppDataSource.getRepository(Assign).findOne({ + select: ["id", "personal_id", "round_no", "date_start", "date_finish"], + where: { id: evaluate.assign_id }, + }); + + if (!assign) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const experimenteeData = await this.personalRepository.findOne({ + where: { + personal_id: assign.personal_id, + }, + }); + + if (!experimenteeData) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const splitOc = await experimenteeData.organization.split(" "); + const splitOcAmount = await splitOc.length; + const organization = await experimenteeData.organization.replace( + /\//g, + " " + ); + + const experimentee = await { + ...experimenteeData, + organization: organization, + name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, + PositionLevelName: experimenteeData.positionLevelName, + PositionLineName: experimenteeData.positionLineName, + Position: experimenteeData.positionName, + Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-", + OrganizationOrganization: + splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-", + Oc: experimenteeData.orgRootName, + PositionLevel: + experimenteeData.positionName + experimenteeData.positionLevelName, + }; + + const data = await { + experimentee: experimentee ? experimentee : null, + director: director ? director : null, + assign, + evaluate: evaluateData, + }; + return new HttpSuccess(data); + } + + /** + * API แสดงข้อมูลแบบประเมินผล (ผู้บังคับบัญชา) ตาม id + * + * @summary ข้อมูลแบบประเมินผล (ผู้บังคับบัญชา) ตาม id + * + */ + @Get("evaluate-commander") + async GetDataEvaluateCommander( + @Query() id: string, + @Request() request: RequestWithUser + ) { + const evaluate = await this.evaluateCommanderRepository.findOne({ + where: { id }, + }); + + if (!evaluate) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const evaluateData = await { + id: evaluate.id, + no: evaluate.no, + date_start: evaluate.date_start, + date_finish: evaluate.date_finish, + sign_dated: evaluate.commander_dated, + knowledge_level: { + col1: evaluate.knowledge_level == 1 ? "/" : "", + col2: evaluate.knowledge_level == 2 ? "/" : "", + col3: evaluate.knowledge_level == 3 ? "/" : "", + col4: evaluate.knowledge_level == 4 ? "/" : "", + col5: evaluate.knowledge_level == 5 ? "/" : "", + }, + skill_level: { + col1: evaluate.skill_level == 1 ? "/" : "", + col2: evaluate.skill_level == 2 ? "/" : "", + col3: evaluate.skill_level == 3 ? "/" : "", + col4: evaluate.skill_level == 4 ? "/" : "", + col5: evaluate.skill_level == 5 ? "/" : "", + }, + competency_level: { + col1: evaluate.competency_level == 1 ? "/" : "", + col2: evaluate.competency_level == 2 ? "/" : "", + col3: evaluate.competency_level == 3 ? "/" : "", + col4: evaluate.competency_level == 4 ? "/" : "", + col5: evaluate.competency_level == 5 ? "/" : "", + }, + learn_level: { + col1: evaluate.learn_level == 1 ? "/" : "", + col2: evaluate.learn_level == 2 ? "/" : "", + col3: evaluate.learn_level == 3 ? "/" : "", + col4: evaluate.learn_level == 4 ? "/" : "", + col5: evaluate.learn_level == 5 ? "/" : "", + }, + apply_level: { + col1: evaluate.apply_level == 1 ? "/" : "", + col2: evaluate.apply_level == 2 ? "/" : "", + col3: evaluate.apply_level == 3 ? "/" : "", + col4: evaluate.apply_level == 4 ? "/" : "", + col5: evaluate.apply_level == 5 ? "/" : "", + }, + success_level: { + col1: evaluate.success_level == 1 ? "/" : "", + col2: evaluate.success_level == 2 ? "/" : "", + col3: evaluate.success_level == 3 ? "/" : "", + col4: evaluate.success_level == 4 ? "/" : "", + col5: evaluate.success_level == 5 ? "/" : "", + }, + achievement_other_desc: evaluate.achievement_other_desc, + achievement_other_level: + evaluate.achievement_other_level != null + ? { + col1: evaluate.achievement_other_level == 1 ? "/" : "", + col2: evaluate.achievement_other_level == 2 ? "/" : "", + col3: evaluate.achievement_other_level == 3 ? "/" : "", + col4: evaluate.achievement_other_level == 4 ? "/" : "", + col5: evaluate.achievement_other_level == 5 ? "/" : "", + } + : { + col1: "", + col2: "", + col3: "", + col4: "", + col5: "", + }, + conduct1_level: { + col1: evaluate.conduct1_level == 1 ? "/" : "", + col2: evaluate.conduct1_level == 2 ? "/" : "", + col3: evaluate.conduct1_level == 3 ? "/" : "", + col4: evaluate.conduct1_level == 4 ? "/" : "", + col5: evaluate.conduct1_level == 5 ? "/" : "", + }, + conduct2_level: { + col1: evaluate.conduct2_level == 1 ? "/" : "", + col2: evaluate.conduct2_level == 2 ? "/" : "", + col3: evaluate.conduct2_level == 3 ? "/" : "", + col4: evaluate.conduct2_level == 4 ? "/" : "", + col5: evaluate.conduct2_level == 5 ? "/" : "", + }, + conduct3_level: { + col1: evaluate.conduct3_level == 1 ? "/" : "", + col2: evaluate.conduct3_level == 2 ? "/" : "", + col3: evaluate.conduct3_level == 3 ? "/" : "", + col4: evaluate.conduct3_level == 4 ? "/" : "", + col5: evaluate.conduct3_level == 5 ? "/" : "", + }, + conduct4_level: { + col1: evaluate.conduct4_level == 1 ? "/" : "", + col2: evaluate.conduct4_level == 2 ? "/" : "", + col3: evaluate.conduct4_level == 3 ? "/" : "", + col4: evaluate.conduct4_level == 4 ? "/" : "", + col5: evaluate.conduct4_level == 5 ? "/" : "", + }, + moral1_level: { + col1: evaluate.moral1_level == 1 ? "/" : "", + col2: evaluate.moral1_level == 2 ? "/" : "", + col3: evaluate.moral1_level == 3 ? "/" : "", + col4: evaluate.moral1_level == 4 ? "/" : "", + col5: evaluate.moral1_level == 5 ? "/" : "", + }, + moral2_level: { + col1: evaluate.moral2_level == 1 ? "/" : "", + col2: evaluate.moral2_level == 2 ? "/" : "", + col3: evaluate.moral2_level == 3 ? "/" : "", + col4: evaluate.moral2_level == 4 ? "/" : "", + col5: evaluate.moral2_level == 5 ? "/" : "", + }, + moral3_level: { + col1: evaluate.moral3_level == 1 ? "/" : "", + col2: evaluate.moral3_level == 2 ? "/" : "", + col3: evaluate.moral3_level == 3 ? "/" : "", + col4: evaluate.moral3_level == 4 ? "/" : "", + col5: evaluate.moral3_level == 5 ? "/" : "", + }, + discipline1_level: { + col1: evaluate.discipline1_level == 1 ? "/" : "", + col2: evaluate.discipline1_level == 2 ? "/" : "", + col3: evaluate.discipline1_level == 3 ? "/" : "", + col4: evaluate.discipline1_level == 4 ? "/" : "", + col5: evaluate.discipline1_level == 5 ? "/" : "", + }, + discipline2_level: { + col1: evaluate.discipline2_level == 1 ? "/" : "", + col2: evaluate.discipline2_level == 2 ? "/" : "", + col3: evaluate.discipline2_level == 3 ? "/" : "", + col4: evaluate.discipline2_level == 4 ? "/" : "", + col5: evaluate.discipline2_level == 5 ? "/" : "", + }, + discipline3_level: { + col1: evaluate.discipline3_level == 1 ? "/" : "", + col2: evaluate.discipline3_level == 2 ? "/" : "", + col3: evaluate.discipline3_level == 3 ? "/" : "", + col4: evaluate.discipline3_level == 4 ? "/" : "", + col5: evaluate.discipline3_level == 5 ? "/" : "", + }, + discipline4_level: { + col1: evaluate.discipline4_level == 1 ? "/" : "", + col2: evaluate.discipline4_level == 2 ? "/" : "", + col3: evaluate.discipline4_level == 3 ? "/" : "", + col4: evaluate.discipline4_level == 4 ? "/" : "", + col5: evaluate.discipline4_level == 5 ? "/" : "", + }, + discipline5_level: { + col1: evaluate.discipline5_level == 1 ? "/" : "", + col2: evaluate.discipline5_level == 2 ? "/" : "", + col3: evaluate.discipline5_level == 3 ? "/" : "", + col4: evaluate.discipline5_level == 4 ? "/" : "", + col5: evaluate.discipline5_level == 5 ? "/" : "", + }, + behavior_other_desc: evaluate.behavior_other_desc, + behavior_other_level: + evaluate.behavior_other_level != null + ? { + col1: evaluate.behavior_other_level == 1 ? "/" : "", + col2: evaluate.behavior_other_level == 2 ? "/" : "", + col3: evaluate.behavior_other_level == 3 ? "/" : "", + col4: evaluate.behavior_other_level == 4 ? "/" : "", + col5: evaluate.behavior_other_level == 5 ? "/" : "", + } + : { + col1: "", + col2: "", + col3: "", + col4: "", + col5: "", + }, + behavior_strength_desc: evaluate.behavior_strength_desc, + behavior_improve_desc: evaluate.behavior_improve_desc, + orientation: evaluate.orientation, + self_learning: evaluate.self_learning, + training_seminar: evaluate.training_seminar, + other_training: evaluate.other_training, + createdAt: evaluate.createdAt, + updatedAt: evaluate.updatedAt, + }; + + const assign = await AppDataSource.getRepository(Assign).findOne({ + select: ["id", "personal_id", "round_no", "date_start", "date_finish"], + where: { id: evaluate.assign_id }, + }); + + if (!assign) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const experimenteeData = await this.personalRepository.findOne({ + where: { + personal_id: assign.personal_id, + }, + }); + + if (!experimenteeData) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const splitOc = await experimenteeData.organization.split(" "); + const splitOcAmount = await splitOc.length; + const organization = await experimenteeData.organization.replace( + /\//g, + " " + ); + + const experimentee = await { + ...experimenteeData, + organization: organization, + name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, + PositionLevelName: experimenteeData.positionLevelName, + PositionLineName: experimenteeData.positionLineName, + Position: experimenteeData.positionName, + Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-", + OrganizationOrganization: + splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-", + Oc: experimenteeData.orgRootName, + PositionLevel: + experimenteeData.positionName + experimenteeData.positionLevelName, + }; + + const commanderData = await this.assignDirectorRepository.findOne({ + select: [ + "personal_id", + "fullname", + "position", + "position", + "posType", + "posLevel", + "role", + "dated", + ], + where: { personal_id: evaluate.director_id }, + }); + + if (!commanderData) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const commander = await { + ...commanderData, + name: commanderData.fullname, + Position: commanderData.position + commanderData.posLevel, + }; + + return new HttpSuccess({ + experimentee: experimentee ? experimentee : null, + commander: commander ? commander : null, + assign, + evaluate: evaluateData, + }); + } + + /** + * API แสดงข้อมูลแบบประเมินผล (คณะกรรมการ) ตาม id + * + * @summary ข้อมูลแบบประเมินผล (คณะกรรมการ) ตาม id + * + */ + @Get("evaluate-chairman") + async GetDataEvaluateChairman( + @Query() id: string, + @Request() request: RequestWithUser + ) { + const evaluate = await this.evaluateChairmanRepository.findOne({ + where: { id }, + }); + + if (!evaluate) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const develop_total_score = await (Number( + evaluate.develop_orientation_score + ) + + Number(evaluate.develop_self_learning_score) + + Number(evaluate.develop_training_seminar_score) + + Number(evaluate.develop_other_training_score)); + const develop_total_percent = await (Number( + evaluate.develop_orientation_percent + ) + + Number(evaluate.develop_orientation_percent) + + Number(evaluate.develop_self_learning_percent) + + Number(evaluate.develop_training_seminar_percent)); + + const evaluateData = await { + id: evaluate.id, + // director_id: evaluate.director_id, + // assign_id: evaluate.assign_id, + no: evaluate.no, + date_start: evaluate.date_start, + date_finish: evaluate.date_finish, + chairman_dated: evaluate.chairman_dated, + director1_dated: evaluate.director1_dated, + director2_dated: evaluate.director2_dated, + knowledge_level: { + col1: evaluate.knowledge_level == 1 ? "/" : "", + col2: evaluate.knowledge_level == 2 ? "/" : "", + col3: evaluate.knowledge_level == 3 ? "/" : "", + col4: evaluate.knowledge_level == 4 ? "/" : "", + col5: evaluate.knowledge_level == 5 ? "/" : "", + }, + apply_level: { + col1: evaluate.apply_level == 1 ? "/" : "", + col2: evaluate.apply_level == 2 ? "/" : "", + col3: evaluate.apply_level == 3 ? "/" : "", + col4: evaluate.apply_level == 4 ? "/" : "", + col5: evaluate.apply_level == 5 ? "/" : "", + }, + success_level: { + col1: evaluate.success_level == 1 ? "/" : "", + col2: evaluate.success_level == 2 ? "/" : "", + col3: evaluate.success_level == 3 ? "/" : "", + col4: evaluate.success_level == 4 ? "/" : "", + col5: evaluate.success_level == 5 ? "/" : "", + }, + achievement_other_desc: evaluate.achievement_other_desc, + achievement_other_level: + evaluate.achievement_other_level != null + ? { + col1: evaluate.achievement_other_level == 1 ? "/" : "", + col2: evaluate.achievement_other_level == 2 ? "/" : "", + col3: evaluate.achievement_other_level == 3 ? "/" : "", + col4: evaluate.achievement_other_level == 4 ? "/" : "", + col5: evaluate.achievement_other_level == 5 ? "/" : "", + } + : { + col1: "", + col2: "", + col3: "", + col4: "", + col5: "", + }, + conduct1_level: { + col1: evaluate.conduct1_level == 1 ? "/" : "", + col2: evaluate.conduct1_level == 2 ? "/" : "", + col3: evaluate.conduct1_level == 3 ? "/" : "", + col4: evaluate.conduct1_level == 4 ? "/" : "", + col5: evaluate.conduct1_level == 5 ? "/" : "", + }, + conduct2_level: { + col1: evaluate.conduct2_level == 1 ? "/" : "", + col2: evaluate.conduct2_level == 2 ? "/" : "", + col3: evaluate.conduct2_level == 3 ? "/" : "", + col4: evaluate.conduct2_level == 4 ? "/" : "", + col5: evaluate.conduct2_level == 5 ? "/" : "", + }, + conduct3_level: { + col1: evaluate.conduct3_level == 1 ? "/" : "", + col2: evaluate.conduct3_level == 2 ? "/" : "", + col3: evaluate.conduct3_level == 3 ? "/" : "", + col4: evaluate.conduct3_level == 4 ? "/" : "", + col5: evaluate.conduct3_level == 5 ? "/" : "", + }, + conduct4_level: { + col1: evaluate.conduct4_level == 1 ? "/" : "", + col2: evaluate.conduct4_level == 2 ? "/" : "", + col3: evaluate.conduct4_level == 3 ? "/" : "", + col4: evaluate.conduct4_level == 4 ? "/" : "", + col5: evaluate.conduct4_level == 5 ? "/" : "", + }, + moral1_level: { + col1: evaluate.moral1_level == 1 ? "/" : "", + col2: evaluate.moral1_level == 2 ? "/" : "", + col3: evaluate.moral1_level == 3 ? "/" : "", + col4: evaluate.moral1_level == 4 ? "/" : "", + col5: evaluate.moral1_level == 5 ? "/" : "", + }, + moral2_level: { + col1: evaluate.moral2_level == 1 ? "/" : "", + col2: evaluate.moral2_level == 2 ? "/" : "", + col3: evaluate.moral2_level == 3 ? "/" : "", + col4: evaluate.moral2_level == 4 ? "/" : "", + col5: evaluate.moral2_level == 5 ? "/" : "", + }, + moral3_level: { + col1: evaluate.moral3_level == 1 ? "/" : "", + col2: evaluate.moral3_level == 2 ? "/" : "", + col3: evaluate.moral3_level == 3 ? "/" : "", + col4: evaluate.moral3_level == 4 ? "/" : "", + col5: evaluate.moral3_level == 5 ? "/" : "", + }, + discipline1_level: { + col1: evaluate.discipline1_level == 1 ? "/" : "", + col2: evaluate.discipline1_level == 2 ? "/" : "", + col3: evaluate.discipline1_level == 3 ? "/" : "", + col4: evaluate.discipline1_level == 4 ? "/" : "", + col5: evaluate.discipline1_level == 5 ? "/" : "", + }, + discipline2_level: { + col1: evaluate.discipline2_level == 1 ? "/" : "", + col2: evaluate.discipline2_level == 2 ? "/" : "", + col3: evaluate.discipline2_level == 3 ? "/" : "", + col4: evaluate.discipline2_level == 4 ? "/" : "", + col5: evaluate.discipline2_level == 5 ? "/" : "", + }, + discipline3_level: { + col1: evaluate.discipline3_level == 1 ? "/" : "", + col2: evaluate.discipline3_level == 2 ? "/" : "", + col3: evaluate.discipline3_level == 3 ? "/" : "", + col4: evaluate.discipline3_level == 4 ? "/" : "", + col5: evaluate.discipline3_level == 5 ? "/" : "", + }, + discipline4_level: { + col1: evaluate.discipline4_level == 1 ? "/" : "", + col2: evaluate.discipline4_level == 2 ? "/" : "", + col3: evaluate.discipline4_level == 3 ? "/" : "", + col4: evaluate.discipline4_level == 4 ? "/" : "", + col5: evaluate.discipline4_level == 5 ? "/" : "", + }, + discipline5_level: { + col1: evaluate.discipline5_level == 1 ? "/" : "", + col2: evaluate.discipline5_level == 2 ? "/" : "", + col3: evaluate.discipline5_level == 3 ? "/" : "", + col4: evaluate.discipline5_level == 4 ? "/" : "", + col5: evaluate.discipline5_level == 5 ? "/" : "", + }, + behavior_other_desc: evaluate.behavior_other_desc, + behavior_other_level: + evaluate.behavior_other_level != null + ? { + col1: evaluate.behavior_other_level == 1 ? "/" : "", + col2: evaluate.behavior_other_level == 2 ? "/" : "", + col3: evaluate.behavior_other_level == 3 ? "/" : "", + col4: evaluate.behavior_other_level == 4 ? "/" : "", + col5: evaluate.behavior_other_level == 5 ? "/" : "", + } + : { + col1: "", + col2: "", + col3: "", + col4: "", + col5: "", + }, + + achievement_score: evaluate.achievement_score, + achievement_score_total: evaluate.achievement_score_total, + achievement_percent: evaluate.achievement_percent, + achievement_result: evaluate.achievement_result, + behavior_score: evaluate.behavior_score, + behavior_score_total: evaluate.behavior_score_total, + behavior_percent: evaluate.behavior_percent, + behavior_result: evaluate.behavior_result, + sum_score: evaluate.sum_score, + sum_percent: evaluate.sum_percent, + + develop_orientation_score: evaluate.develop_orientation_score, + develop_self_learning_score: evaluate.develop_self_learning_score, + develop_training_seminar_score: evaluate.develop_training_seminar_score, + develop_other_training_score: evaluate.develop_other_training_score, + develop_total_score: develop_total_score, + develop_orientation_percent: evaluate.develop_orientation_percent, + develop_self_learning_percent: evaluate.develop_self_learning_percent, + develop_training_seminar_percent: + evaluate.develop_training_seminar_percent, + develop_other_training_percent: evaluate.develop_other_training_percent, + develop_total_percent: develop_total_percent, + develop_result: evaluate.develop_result, + evaluate_result: evaluate.evaluate_result, + createdAt: evaluate.createdAt, + updatedAt: evaluate.updatedAt, + }; + + const assign = await AppDataSource.getRepository(Assign).findOne({ + select: ["id", "personal_id", "round_no", "date_start", "date_finish"], + where: { id: evaluate.assign_id }, + }); + + if (!assign) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const experimenteeData = await this.personalRepository.findOne({ + where: { + personal_id: assign.personal_id, + }, + }); + + if (!experimenteeData) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const splitOc = await experimenteeData.organization.split(" "); + const splitOcAmount = await splitOc.length; + const organization = await experimenteeData.organization.replace( + /\//g, + " " + ); + + const experimentee = await { + ...experimenteeData, + organization: organization, + name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, + PositionLevelName: experimenteeData.positionLevelName, + PositionLineName: experimenteeData.positionLineName, + Position: experimenteeData.positionName, + Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-", + OrganizationOrganization: + splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-", + Oc: experimenteeData.orgRootName, + PositionLevel: + experimenteeData.positionName + experimenteeData.positionLevelName, + }; + + const directorData = await this.assignDirectorRepository.find({ + select: [ + "personal_id", + "fullname", + "position", + "posType", + "posLevel", + "role", + "dated", + ], + where: { assign_id: assign.id }, + }); + + if (!directorData) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const director = await Promise.all( + directorData.map(async (element) => { + return { + ...element, + name: element.fullname, + Position: element.position + element.posLevel, + }; + }) + ); + + const mentorData = await (director.find((x) => x.role == "mentor") ?? null); + const mentor = mentorData != null ? mentorData : null; + + const commanderData = await (director.find((x) => x.role == "commander") ?? + null); + const commander = commanderData != null ? commanderData : null; + + const chairmanData = await (director.find((x) => x.role == "chairman") ?? + null); + const chairman = chairmanData != null ? chairmanData : null; + + return new HttpSuccess({ + experimentee: experimentee ? experimentee : null, + chairman: chairman ? chairman : null, + director1: commander ? commander : null, + director2: mentor ? mentor : null, + assign, + evaluate: evaluateData, + }); + } + + @Post("command11/officer/report/excecute") + public async command11Excecute( + @Request() request: RequestWithUser, + @Body() + body: { + refIds: { + refId: string; + commandNo: string | null; + commandYear: number | null; + commandId: string | null; + remark: string | null; + amount: Double | null; + amountSpecial?: Double | null; + positionSalaryAmount: Double | null; + mouthSalaryAmount: Double | null; commandCode?: string | null; commandName?: string | null; - templateDoc?: string | null - amount: Double | null - amountSpecial?: Double | null - positionSalaryAmount: Double | null - mouthSalaryAmount: Double | null - mpCee?: string | null - refCommandCode?: string | null - refCommandName?: string | null - remark?: string | null - }[] - } - ) { - const lists = await this.appointRepository.find({ - where: { id: In(body.refIds.map(x => x.refId)) }, - }) - await Promise.all( - lists.map(async list => { - list.status = "DONE" - list.commandNo = `${body?.refIds[0]?.commandNo || ""}/${body.refIds[0].commandYear + 543}` - await this.appointRepository.save(list) - }) - ) - return new HttpSuccess() - } - @Post("command10/officer/report") - public async command10( - @Request() req: RequestWithUser, - @Body() - body: { - refIds: string[] - } - ) { - const lists = await this.appointRepository.find({ - where: { id: In(body.refIds) }, - }) - await Promise.all( - lists.map(async list => { - list.status = "REPORT" - await this.appointRepository.save(list) - }) - ) - return new HttpSuccess() - } - @Post("command10/officer/report/delete") - public async command10Delete( - @Request() req: RequestWithUser, - @Body() - body: { - refIds: string[] - } - ) { - const lists = await this.appointRepository.find({ - where: { id: In(body.refIds) }, - }) - await Promise.all( - lists.map(async list => { - list.status = "PENDING" - await this.appointRepository.save(list) - }) - ) - return new HttpSuccess() - } + commandDateAffect: Date | null; + commandDateSign: Date | null; + }[]; + } + ) { + await new CallAPI() + .PostData(request, "/org/command/excexute/salary-probation", { + data: body.refIds.map((v) => ({ + profileId: v.refId, + commandId: v.commandId, + amount: v.amount, + amountSpecial: v.amountSpecial, + positionSalaryAmount: v.positionSalaryAmount, + mouthSalaryAmount: v.mouthSalaryAmount, + commandNo: v.commandNo, + commandYear: v.commandYear, + commandDateAffect: v.commandDateAffect, + commandDateSign: v.commandDateSign, + commandCode: v.commandCode, + commandName: v.commandName, + remark: v.remark, + })), + }) + .then(async (res) => { + const lists = await this.personalRepository.find({ + where: { + probation_status: 8, + personal_id: In(body.refIds.map((x) => x.refId)), + }, + }); + await Promise.all( + lists.map(async (list) => { + list.probation_status = 9; + await this.personalRepository.save(list); + }) + ); + }) + .catch(() => {}); + return new HttpSuccess(); + } + @Post("command11/officer/report") + public async command11( + @Request() req: RequestWithUser, + @Body() + body: { + refIds: string[]; + } + ) { + const lists = await this.personalRepository.find({ + where: { probation_status: 2, personal_id: In(body.refIds) }, + }); + await Promise.all( + lists.map(async (list) => { + list.probation_status = 8; + await this.personalRepository.save(list); + }) + ); - @Get("command10/appoints/{refId}") - public async appointList(@Request() req: RequestWithUser, @Path() refId: string) { - const lists = await this.AppointDirectorRepository.find({ - where: { appointId: refId }, - order: { createdAt: "ASC" }, - }) - const directors = await Promise.all( - lists.map(async director => { - return { - profileId: director.profileId, - name: director.name, - position: director.position, - positionType: director.positionType, - positionLevel: director.positionLevel, - role: director.role === "chairman" ? "ประธาน" : "กรรมการ", - } - }) - ) - return new HttpSuccess(directors) - } + return new HttpSuccess(); + } + @Post("command11/officer/report/delete") + public async command11Delete( + @Request() req: RequestWithUser, + @Body() + body: { + refIds: string[]; + } + ) { + const lists = await this.personalRepository.find({ + where: { probation_status: 8, personal_id: In(body.refIds) }, + }); + await Promise.all( + lists.map(async (list) => { + list.probation_status = 2; + await this.personalRepository.save(list); + }) + ); - @Get("report1") - public async report1(@Request() req: RequestWithUser, @Query("nodeId") nodeId?: string, @Query("node") node?: string, @Query("startDate") startDate?: Date, @Query("endDate") endDate?: Date) { - interface Result { - [rootDnaId: string]: { - rootName: string - status1: number - status2: number - status3: number - status4: number - status5: number - status6: number - status7: number - } - } + return new HttpSuccess(); + } - const rootNode = await new CallAPI().PostData(req, "/org/find/node-all", { nodeId: nodeId, node: node }).catch(error => { - console.error("Error calling API:", error) - }) - const rootNodeTrue = rootNode["isRootTrue"] - const rootNodeFalse = rootNode["isRootFalse"] + @Post("command12/officer/report/excecute") + public async command12Excecute( + @Request() request: RequestWithUser, + @Body() + body: { + refIds: { + refId: string; + commandNo: string | null; + commandYear: number | null; + commandId: string | null; + remark: string | null; + amount: Double | null; + amountSpecial?: Double | null; + positionSalaryAmount: Double | null; + mouthSalaryAmount: Double | null; + commandCode?: string | null; + commandName?: string | null; + commandDateAffect: Date | null; + commandDateSign: Date | null; + }[]; + } + ) { + await new CallAPI() + .PostData(request, "/org/command/excexute/salary-probation-leave", { + data: body.refIds.map((v) => ({ + profileId: v.refId, + commandId: v.commandId, + amount: v.amount, + amountSpecial: v.amountSpecial, + positionSalaryAmount: v.positionSalaryAmount, + mouthSalaryAmount: v.mouthSalaryAmount, + isGovernment: false, + commandNo: v.commandNo, + commandYear: v.commandYear, + commandDateAffect: v.commandDateAffect, + commandDateSign: v.commandDateSign, + commandCode: v.commandCode, + commandName: v.commandName, + remark: v.remark, + })), + }) + .then(async (res) => { + const lists = await this.personalRepository.find({ + where: { + probation_status: 8, + personal_id: In(body.refIds.map((x) => x.refId)), + }, + }); + await Promise.all( + lists.map(async (list) => { + list.probation_status = 9; + await this.personalRepository.save(list); + }) + ); + }) + .catch(() => {}); + return new HttpSuccess(); + } + @Post("command12/officer/report") + public async command12( + @Request() req: RequestWithUser, + @Body() + body: { + refIds: string[]; + } + ) { + const lists = await this.personalRepository.find({ + where: { probation_status: 3, personal_id: In(body.refIds) }, + }); + await Promise.all( + lists.map(async (list) => { + list.probation_status = 8; + await this.personalRepository.save(list); + }) + ); + return new HttpSuccess(); + } + @Post("command12/officer/report/delete") + public async command12Delete( + @Request() req: RequestWithUser, + @Body() + body: { + refIds: string[]; + } + ) { + const lists = await this.personalRepository.find({ + where: { probation_status: 8, personal_id: In(body.refIds) }, + }); + await Promise.all( + lists.map(async (list) => { + list.probation_status = 3; + await this.personalRepository.save(list); + }) + ); + return new HttpSuccess(); + } - let whereRootTrue = rootNodeTrue && rootNodeTrue.rootDnaId ? { rootDna: rootNodeTrue.rootDnaId } : {} - let listsRootTrue = - rootNodeTrue && rootNodeTrue.rootDnaId - ? await this.personalRepository.find({ - where: { - ...whereRootTrue, - createdAt: startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : undefined, - }, - }) - : [] + @Post("command10/officer/report/excecute") + public async command10Excecute( + @Request() request: RequestWithUser, + @Body() + body: { + refIds: { + refId: string; + // commandAffectDate: Date | null //เก่า + commandDateAffect: Date | null; //ใหม่ปรับตาม RabbitMQ ORG + commandDateSign?: Date | null; + commandNo: string | null; + commandId?: string | null; + commandYear: number; + commandCode?: string | null; + commandName?: string | null; + templateDoc?: string | null; + amount: Double | null; + amountSpecial?: Double | null; + positionSalaryAmount: Double | null; + mouthSalaryAmount: Double | null; + mpCee?: string | null; + refCommandCode?: string | null; + refCommandName?: string | null; + remark?: string | null; + }[]; + } + ) { + const lists = await this.appointRepository.find({ + where: { id: In(body.refIds.map((x) => x.refId)) }, + }); + await Promise.all( + lists.map(async (list) => { + list.status = "DONE"; + list.commandNo = `${body?.refIds[0]?.commandNo || ""}/${body.refIds[0].commandYear + 543}`; + await this.appointRepository.save(list); + }) + ); + return new HttpSuccess(); + } + @Post("command10/officer/report") + public async command10( + @Request() req: RequestWithUser, + @Body() + body: { + refIds: string[]; + } + ) { + const lists = await this.appointRepository.find({ + where: { id: In(body.refIds) }, + }); + await Promise.all( + lists.map(async (list) => { + list.status = "REPORT"; + await this.appointRepository.save(list); + }) + ); + return new HttpSuccess(); + } + @Post("command10/officer/report/delete") + public async command10Delete( + @Request() req: RequestWithUser, + @Body() + body: { + refIds: string[]; + } + ) { + const lists = await this.appointRepository.find({ + where: { id: In(body.refIds) }, + }); + await Promise.all( + lists.map(async (list) => { + list.status = "PENDING"; + await this.appointRepository.save(list); + }) + ); + return new HttpSuccess(); + } - let rootDnaIds = rootNodeFalse.map((node: any) => node.rootDnaId) - let listsRootFalse = - rootDnaIds && rootDnaIds.length - ? await this.personalRepository.find({ - where: { - rootDna: In(rootDnaIds), - createdAt: startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : undefined, - }, - }) - : [] + @Get("command10/appoints/{refId}") + public async appointList( + @Request() req: RequestWithUser, + @Path() refId: string + ) { + const lists = await this.AppointDirectorRepository.find({ + where: { appointId: refId }, + order: { createdAt: "ASC" }, + }); + const directors = await Promise.all( + lists.map(async (director) => { + return { + profileId: director.profileId, + name: director.name, + position: director.position, + positionType: director.positionType, + positionLevel: director.positionLevel, + role: director.role === "chairman" ? "ประธาน" : "กรรมการ", + }; + }) + ); + return new HttpSuccess(directors); + } - let resultTrue: Result = {} - let resultFalse: Result = {} + @Get("report1") + public async report1( + @Request() req: RequestWithUser, + @Query("nodeId") nodeId?: string, + @Query("node") node?: string, + @Query("startDate") startDate?: Date, + @Query("endDate") endDate?: Date + ) { + interface Result { + [rootDnaId: string]: { + rootName: string; + status1: number; + status2: number; + status3: number; + status4: number; + status5: number; + status6: number; + status7: number; + }; + } - listsRootTrue.forEach(item => { - let rootDnaId = item.rootDna - let status = item.probation_status - let rootName = item.orgRootName + const rootNode = await new CallAPI() + .PostData(req, "/org/find/node-all", { nodeId: nodeId, node: node }) + .catch((error) => { + console.error("Error calling API:", error); + }); + const rootNodeTrue = rootNode["isRootTrue"]; + const rootNodeFalse = rootNode["isRootFalse"]; - if (!resultTrue[rootDnaId]) { - resultTrue[rootDnaId] = { - rootName: rootName, - status1: 0, - status2: 0, - status3: 0, - status4: 0, - status5: 0, - status6: 0, - status7: 0, - } - } + let whereRootTrue = + rootNodeTrue && rootNodeTrue.rootDnaId + ? { rootDna: rootNodeTrue.rootDnaId } + : {}; + let listsRootTrue = + rootNodeTrue && rootNodeTrue.rootDnaId + ? await this.personalRepository.find({ + where: { + ...whereRootTrue, + createdAt: + startDate && endDate + ? Between(new Date(startDate), new Date(endDate)) + : undefined, + }, + }) + : []; - if (status >= 1 && status <= 7) { - ;(resultTrue[rootDnaId] as { [key: string]: any })[`status${status}`]++ - } - }) - listsRootFalse.forEach(item => { - let rootDnaId = item.rootDna - let status = item.probation_status - let rootName = item.orgRootName + let rootDnaIds = rootNodeFalse.map((node: any) => node.rootDnaId); + let listsRootFalse = + rootDnaIds && rootDnaIds.length + ? await this.personalRepository.find({ + where: { + rootDna: In(rootDnaIds), + createdAt: + startDate && endDate + ? Between(new Date(startDate), new Date(endDate)) + : undefined, + }, + }) + : []; - if (!resultFalse[rootDnaId]) { - resultFalse[rootDnaId] = { - rootName: rootName, - status1: 0, - status2: 0, - status3: 0, - status4: 0, - status5: 0, - status6: 0, - status7: 0, - } - } + let resultTrue: Result = {}; + let resultFalse: Result = {}; - if (status >= 1 && status <= 7) { - ;(resultFalse[rootDnaId] as { [key: string]: any })[`status${status}`]++ - } - }) - const resultTruePass = Object.values(resultTrue).reduce((sum, { status2 }) => sum + status2, 0) - const resultTrueExtand = Object.values(resultTrue).reduce((sum, { status7 }) => sum + status7, 0) - const resultTrueSuspension = "-" - const resultTrueChangePos = Object.values(resultTrue).reduce((sum, { status4 }) => sum + status4, 0) - const resultTrueResign = Object.values(resultTrue).reduce((sum, { status5 }) => sum + status5, 0) - const resultTrueDeceased = Object.values(resultTrue).reduce((sum, { status6 }) => sum + status6, 0) - const resultTrueNotPass = Object.values(resultTrue).reduce((sum, { status3 }) => sum + status3, 0) - const resultFalsePass = Object.values(resultFalse).reduce((sum, { status2 }) => sum + status2, 0) - const resultFalseExtand = Object.values(resultFalse).reduce((sum, { status7 }) => sum + status7, 0) - const resultFalseSuspension = "-" - const resultFalseChangePos = Object.values(resultFalse).reduce((sum, { status4 }) => sum + status4, 0) - const resultFalseResign = Object.values(resultFalse).reduce((sum, { status5 }) => sum + status5, 0) - const resultFalseDeceased = Object.values(resultFalse).reduce((sum, { status6 }) => sum + status6, 0) - const resultFalseNotPass = Object.values(resultFalse).reduce((sum, { status3 }) => sum + status3, 0) - const sumPass = Object.values(resultTrue).reduce((sum, { status2 }) => sum + status2, 0) + Object.values(resultFalse).reduce((sum, { status2 }) => sum + status2, 0) - const sumExtand = Object.values(resultTrue).reduce((sum, { status7 }) => sum + status7, 0) + Object.values(resultFalse).reduce((sum, { status7 }) => sum + status7, 0) - const sumSuspension = "-" - const sumChangePos = Object.values(resultTrue).reduce((sum, { status4 }) => sum + status4, 0) + Object.values(resultFalse).reduce((sum, { status4 }) => sum + status4, 0) - const sumResign = Object.values(resultTrue).reduce((sum, { status5 }) => sum + status5, 0) + Object.values(resultFalse).reduce((sum, { status5 }) => sum + status5, 0) - const sumDeceased = Object.values(resultTrue).reduce((sum, { status6 }) => sum + status6, 0) + Object.values(resultFalse).reduce((sum, { status6 }) => sum + status6, 0) - const sumNotPass = Object.values(resultTrue).reduce((sum, { status3 }) => sum + status3, 0) + Object.values(resultFalse).reduce((sum, { status3 }) => sum + status3, 0) - const sumResultTrue = Object.values(resultTrue).reduce((total, { status2, status7, status4, status5, status6, status3 }) => { - return total + status2 + status7 + status4 + status5 + status6 + status3 - }, 0) - const sumResultFalse = Object.values(resultFalse).reduce((total, { status2, status7, status4, status5, status6, status3 }) => { - return total + status2 + status7 + status4 + status5 + status6 + status3 - }, 0) - const sumAll = sumPass + sumExtand + sumChangePos + sumResign + sumDeceased + sumNotPass - const nowDate = Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())) - const formattedData = { - topic: "หน่วยงานระดับสำนักหรือเทียบเท่า", - dateNow: nowDate, - dateStart: startDate ? Extension.ToThaiNumber(Extension.ToThaiNoprefixDate(startDate)) : "", - dateEnd: endDate ? Extension.ToThaiNumber(Extension.ToThaiNoprefixDate(endDate)) : "", - resultTrueProbation: Object.keys(resultTrue).map((rootDnaId, index) => { - const { status2, status7, status4, status5, status6, status3, rootName } = resultTrue[rootDnaId] - const sum = status2 + status7 + status4 + status5 + status6 + status3 - return { - rowNo: (index + 1).toString(), - rootName: rootName.toString(), - pass: status2.toString(), - extand: status7.toString(), - suspension: "-", - changePos: status4.toString(), - resign: status5.toString(), - deceased: status6.toString(), - notPass: status3.toString(), - total: sum.toString(), - } - }), - resultTruePass: resultTruePass.toString(), - resultTrueExtand: resultTrueExtand.toString(), - resultTrueSuspension: "-", - resultTrueChangePos: resultTrueChangePos.toString(), - resultTrueResign: resultTrueResign.toString(), - resultTrueDeceased: resultTrueDeceased.toString(), - resultTrueNotPass: resultTrueNotPass.toString(), - topic2: "หน่วยงานระดับสำนักงานเขต", - resultFalseProbation: Object.keys(resultFalse).map((rootDnaId, index) => { - const { status2, status7, status4, status5, status6, status3, rootName } = resultFalse[rootDnaId] - const sum = status2 + status7 + status4 + status5 + status6 + status3 - return { - rowNo: (index + 1).toString(), - rootName: rootName.toString(), - pass: status2.toString(), - extand: status7.toString(), - suspension: "-", - changePos: status4.toString(), - resign: status5.toString(), - deceased: status6.toString(), - notPass: status3.toString(), - total: sum.toString(), - } - }), - resultFalsePass: resultFalsePass.toString(), - resultFalseExtand: resultFalseExtand.toString(), - resultFalseSuspension: "-", - resultFalseChangePos: resultFalseChangePos.toString(), - resultFalseResign: resultFalseResign.toString(), - resultFalseDeceased: resultFalseDeceased.toString(), - resultFalseNotPass: resultFalseNotPass.toString(), - sumPass: sumPass.toString(), - sumExtand: sumExtand.toString(), - sumSuspension: "-", - sumChangePos: sumChangePos.toString(), - sumResign: sumResign.toString(), - sumDeceased: sumDeceased.toString(), - sumNotPass: sumNotPass.toString(), - sumResultTrue: sumResultTrue.toString(), - sumResultFalse: sumResultFalse.toString(), - sumAll: sumAll.toString(), - } - return new HttpSuccess({ - template: "placementProbation01", - reportName: "xlsx-report", - data: formattedData, - }) - } + listsRootTrue.forEach((item) => { + let rootDnaId = item.rootDna; + let status = item.probation_status; + let rootName = item.orgRootName; - @Get("report2") - public async report2(@Request() req: RequestWithUser, @Query("nodeId") nodeId?: string, @Query("node") node?: number, @Query("startDate") startDate?: Date, @Query("endDate") endDate?: Date) { - let personal = null - let result: Array = [] - switch (node) { - case 0: { - personal = await this.personalRepository.find({ - where: { - rootDna: nodeId, - createdAt: startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : Not(IsNull()), - }, - }) - personal = await Promise.all( - personal.map(async (p, idx) => { - const assigns = await this.assignRepository.find({ - where: { personal_id: p.personal_id }, - }) - const no = idx + 1 - return { - no: no, - fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, - positionName: p.positionName, - organization: p.organization, - probation_status: p.probation_status, - idcard: p.idcard, - assigns: assigns, - } - }) - ) - break - } - case 1: { - personal = await this.personalRepository.find({ - where: { - child1Dna: nodeId, - createdAt: startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : Not(IsNull()), - }, - }) - personal = await Promise.all( - personal.map(async (p, idx) => { - const assigns = await this.assignRepository.find({ - where: { personal_id: p.personal_id }, - }) - const no = idx + 1 - return { - no: no, - fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, - positionName: p.positionName, - organization: p.organization, - probation_status: p.probation_status, - idcard: p.idcard, - assigns: assigns, - } - }) - ) - break - } - case 2: { - personal = await this.personalRepository.find({ - where: { - child2Dna: nodeId, - createdAt: startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : Not(IsNull()), - }, - }) - personal = await Promise.all( - personal.map(async (p, idx) => { - const assigns = await this.assignRepository.find({ - where: { personal_id: p.personal_id }, - }) - const no = idx + 1 - return { - no: no, - fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, - positionName: p.positionName, - organization: p.organization, - probation_status: p.probation_status, - idcard: p.idcard, - assigns: assigns, - } - }) - ) - break - } - case 3: { - personal = await this.personalRepository.find({ - where: { - child3Dna: nodeId, - createdAt: startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : Not(IsNull()), - }, - }) - personal = await Promise.all( - personal.map(async (p, idx) => { - const assigns = await this.assignRepository.find({ - where: { personal_id: p.personal_id }, - }) - const no = idx + 1 - return { - no: no, - fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, - positionName: p.positionName, - organization: p.organization, - probation_status: p.probation_status, - idcard: p.idcard, - assigns: assigns, - } - }) - ) - break - } - case 4: { - personal = await this.personalRepository.find({ - where: { - child4Dna: nodeId, - createdAt: startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : Not(IsNull()), - }, - }) - personal = await Promise.all( - personal.map(async (p, idx) => { - const assigns = await this.assignRepository.find({ - where: { personal_id: p.personal_id }, - }) - const no = idx + 1 - return { - no: no, - fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, - positionName: p.positionName, - organization: p.organization, - probation_status: p.probation_status, - idcard: p.idcard, - assigns: assigns, - } - }) - ) - break - } - default: { - personal = await this.personalRepository.find({}) - personal = await Promise.all( - personal.map(async (p, idx) => { - const assigns = await this.assignRepository.find({ - where: { personal_id: p.personal_id }, - }) - const no = idx + 1 - return { - no: no, - fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, - positionName: p.positionName, - organization: p.organization, - probation_status: p.probation_status, - idcard: p.idcard, - assigns: assigns, - } - }) - ) - } - } + if (!resultTrue[rootDnaId]) { + resultTrue[rootDnaId] = { + rootName: rootName, + status1: 0, + status2: 0, + status3: 0, + status4: 0, + status5: 0, + status6: 0, + status7: 0, + }; + } - result = await Promise.all( - personal.flatMap(x => - (x.assigns.length > 0 ? x.assigns : [{ id: null, date_start: null, date_finish: null }]).map(async assign => { - let accExam: string = "" - let dateAppoint: Date | any = null - await new CallAPI() - .GetData(req, `/placement/exam-probation/${x.idcard}`) - .then(async x => { - accExam = x.examName - dateAppoint = x.dateAppoint - }) - .catch(errr => {}) + if (status >= 1 && status <= 7) { + (resultTrue[rootDnaId] as { [key: string]: any })[`status${status}`]++; + } + }); + listsRootFalse.forEach((item) => { + let rootDnaId = item.rootDna; + let status = item.probation_status; + let rootName = item.orgRootName; - const evaluateComman = await this.evaluateCommanderRepository.findOne({ - where: { assign_id: assign.id ?? "" }, - }) + if (!resultFalse[rootDnaId]) { + resultFalse[rootDnaId] = { + rootName: rootName, + status1: 0, + status2: 0, + status3: 0, + status4: 0, + status5: 0, + status6: 0, + status7: 0, + }; + } - return { - no: Extension.ToThaiNumber(x.no.toString()), - accExam: accExam, - fullName: x.fullName, - positionName: x.positionName, - organization: x.organization, - dateAppoint: dateAppoint ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(dateAppoint)) : "", - dateStart: x.assigns.length > 0 && assign.date_start != null ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(assign.date_start)) : "", - dateFinish: x.assigns.length > 0 && assign.date_finish != null ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(assign.date_finish)) : "", - day: - x.assigns.length > 0 && assign.date_start != null && assign.date_finish != null - ? Extension.ToThaiNumber(`${Math.ceil((new Date(assign.date_finish).getTime() - new Date(assign.date_start).getTime()) / (1000 * 60 * 60 * 24))} วัน`) - : "", - status: x.probation_status ? Extension.probationStatus(x.probation_status) : "", - orientation: evaluateComman && evaluateComman?.orientation == 1 ? "☑" : "☐", - learning: evaluateComman && evaluateComman?.self_learning == 1 ? "☑" : "☐", - seminar: evaluateComman && evaluateComman?.training_seminar == 1 ? "☑" : "☐", - other: evaluateComman && evaluateComman?.other_training == 1 ? "☑" : "☐", - } - }) - ) - ) + if (status >= 1 && status <= 7) { + (resultFalse[rootDnaId] as { [key: string]: any })[`status${status}`]++; + } + }); + const resultTruePass = Object.values(resultTrue).reduce( + (sum, { status2 }) => sum + status2, + 0 + ); + const resultTrueExtand = Object.values(resultTrue).reduce( + (sum, { status7 }) => sum + status7, + 0 + ); + const resultTrueSuspension = "-"; + const resultTrueChangePos = Object.values(resultTrue).reduce( + (sum, { status4 }) => sum + status4, + 0 + ); + const resultTrueResign = Object.values(resultTrue).reduce( + (sum, { status5 }) => sum + status5, + 0 + ); + const resultTrueDeceased = Object.values(resultTrue).reduce( + (sum, { status6 }) => sum + status6, + 0 + ); + const resultTrueNotPass = Object.values(resultTrue).reduce( + (sum, { status3 }) => sum + status3, + 0 + ); + const resultFalsePass = Object.values(resultFalse).reduce( + (sum, { status2 }) => sum + status2, + 0 + ); + const resultFalseExtand = Object.values(resultFalse).reduce( + (sum, { status7 }) => sum + status7, + 0 + ); + const resultFalseSuspension = "-"; + const resultFalseChangePos = Object.values(resultFalse).reduce( + (sum, { status4 }) => sum + status4, + 0 + ); + const resultFalseResign = Object.values(resultFalse).reduce( + (sum, { status5 }) => sum + status5, + 0 + ); + const resultFalseDeceased = Object.values(resultFalse).reduce( + (sum, { status6 }) => sum + status6, + 0 + ); + const resultFalseNotPass = Object.values(resultFalse).reduce( + (sum, { status3 }) => sum + status3, + 0 + ); + const sumPass = + Object.values(resultTrue).reduce((sum, { status2 }) => sum + status2, 0) + + Object.values(resultFalse).reduce((sum, { status2 }) => sum + status2, 0); + const sumExtand = + Object.values(resultTrue).reduce((sum, { status7 }) => sum + status7, 0) + + Object.values(resultFalse).reduce((sum, { status7 }) => sum + status7, 0); + const sumSuspension = "-"; + const sumChangePos = + Object.values(resultTrue).reduce((sum, { status4 }) => sum + status4, 0) + + Object.values(resultFalse).reduce((sum, { status4 }) => sum + status4, 0); + const sumResign = + Object.values(resultTrue).reduce((sum, { status5 }) => sum + status5, 0) + + Object.values(resultFalse).reduce((sum, { status5 }) => sum + status5, 0); + const sumDeceased = + Object.values(resultTrue).reduce((sum, { status6 }) => sum + status6, 0) + + Object.values(resultFalse).reduce((sum, { status6 }) => sum + status6, 0); + const sumNotPass = + Object.values(resultTrue).reduce((sum, { status3 }) => sum + status3, 0) + + Object.values(resultFalse).reduce((sum, { status3 }) => sum + status3, 0); + const sumResultTrue = Object.values(resultTrue).reduce( + (total, { status2, status7, status4, status5, status6, status3 }) => { + return ( + total + status2 + status7 + status4 + status5 + status6 + status3 + ); + }, + 0 + ); + const sumResultFalse = Object.values(resultFalse).reduce( + (total, { status2, status7, status4, status5, status6, status3 }) => { + return ( + total + status2 + status7 + status4 + status5 + status6 + status3 + ); + }, + 0 + ); + const sumAll = + sumPass + sumExtand + sumChangePos + sumResign + sumDeceased + sumNotPass; + const nowDate = Extension.ToThaiNumber( + Extension.ToThaiShortDate(new Date()) + ); + const formattedData = { + topic: "หน่วยงานระดับสำนักหรือเทียบเท่า", + dateNow: nowDate, + dateStart: startDate + ? Extension.ToThaiNumber(Extension.ToThaiNoprefixDate(startDate)) + : "", + dateEnd: endDate + ? Extension.ToThaiNumber(Extension.ToThaiNoprefixDate(endDate)) + : "", + resultTrueProbation: Object.keys(resultTrue).map((rootDnaId, index) => { + const { + status2, + status7, + status4, + status5, + status6, + status3, + rootName, + } = resultTrue[rootDnaId]; + const sum = status2 + status7 + status4 + status5 + status6 + status3; + return { + rowNo: (index + 1).toString(), + rootName: rootName.toString(), + pass: status2.toString(), + extand: status7.toString(), + suspension: "-", + changePos: status4.toString(), + resign: status5.toString(), + deceased: status6.toString(), + notPass: status3.toString(), + total: sum.toString(), + }; + }), + resultTruePass: resultTruePass.toString(), + resultTrueExtand: resultTrueExtand.toString(), + resultTrueSuspension: "-", + resultTrueChangePos: resultTrueChangePos.toString(), + resultTrueResign: resultTrueResign.toString(), + resultTrueDeceased: resultTrueDeceased.toString(), + resultTrueNotPass: resultTrueNotPass.toString(), + topic2: "หน่วยงานระดับสำนักงานเขต", + resultFalseProbation: Object.keys(resultFalse).map((rootDnaId, index) => { + const { + status2, + status7, + status4, + status5, + status6, + status3, + rootName, + } = resultFalse[rootDnaId]; + const sum = status2 + status7 + status4 + status5 + status6 + status3; + return { + rowNo: (index + 1).toString(), + rootName: rootName.toString(), + pass: status2.toString(), + extand: status7.toString(), + suspension: "-", + changePos: status4.toString(), + resign: status5.toString(), + deceased: status6.toString(), + notPass: status3.toString(), + total: sum.toString(), + }; + }), + resultFalsePass: resultFalsePass.toString(), + resultFalseExtand: resultFalseExtand.toString(), + resultFalseSuspension: "-", + resultFalseChangePos: resultFalseChangePos.toString(), + resultFalseResign: resultFalseResign.toString(), + resultFalseDeceased: resultFalseDeceased.toString(), + resultFalseNotPass: resultFalseNotPass.toString(), + sumPass: sumPass.toString(), + sumExtand: sumExtand.toString(), + sumSuspension: "-", + sumChangePos: sumChangePos.toString(), + sumResign: sumResign.toString(), + sumDeceased: sumDeceased.toString(), + sumNotPass: sumNotPass.toString(), + sumResultTrue: sumResultTrue.toString(), + sumResultFalse: sumResultFalse.toString(), + sumAll: sumAll.toString(), + }; + return new HttpSuccess({ + template: "placementProbation01", + reportName: "xlsx-report", + data: formattedData, + }); + } - return new HttpSuccess({ - template: "placementProbation02", - reportName: "xlsx-report", - data: { - date: `ตั้งแต่${Extension.ToThaiNumber(Extension.ToThaiNoprefixDate2(startDate ?? new Date()))} ถึง ${Extension.ToThaiNumber(Extension.ToThaiNoprefixDate2(endDate ?? new Date()))}`, - dateCurrent: `ณ ${Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date()))}`, - data: result, - }, - }) - } + @Get("report2") + public async report2( + @Request() req: RequestWithUser, + @Query("nodeId") nodeId?: string, + @Query("node") node?: number, + @Query("startDate") startDate?: Date, + @Query("endDate") endDate?: Date + ) { + let personal = null; + let result: Array = []; + switch (node) { + case 0: { + personal = await this.personalRepository.find({ + where: { + rootDna: nodeId, + createdAt: + startDate && endDate + ? Between(new Date(startDate), new Date(endDate)) + : Not(IsNull()), + }, + }); + personal = await Promise.all( + personal.map(async (p, idx) => { + const assigns = await this.assignRepository.find({ + where: { personal_id: p.personal_id }, + }); + const no = idx + 1; + return { + no: no, + fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, + positionName: p.positionName, + organization: p.organization, + probation_status: p.probation_status, + idcard: p.idcard, + assigns: assigns, + }; + }) + ); + break; + } + case 1: { + personal = await this.personalRepository.find({ + where: { + child1Dna: nodeId, + createdAt: + startDate && endDate + ? Between(new Date(startDate), new Date(endDate)) + : Not(IsNull()), + }, + }); + personal = await Promise.all( + personal.map(async (p, idx) => { + const assigns = await this.assignRepository.find({ + where: { personal_id: p.personal_id }, + }); + const no = idx + 1; + return { + no: no, + fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, + positionName: p.positionName, + organization: p.organization, + probation_status: p.probation_status, + idcard: p.idcard, + assigns: assigns, + }; + }) + ); + break; + } + case 2: { + personal = await this.personalRepository.find({ + where: { + child2Dna: nodeId, + createdAt: + startDate && endDate + ? Between(new Date(startDate), new Date(endDate)) + : Not(IsNull()), + }, + }); + personal = await Promise.all( + personal.map(async (p, idx) => { + const assigns = await this.assignRepository.find({ + where: { personal_id: p.personal_id }, + }); + const no = idx + 1; + return { + no: no, + fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, + positionName: p.positionName, + organization: p.organization, + probation_status: p.probation_status, + idcard: p.idcard, + assigns: assigns, + }; + }) + ); + break; + } + case 3: { + personal = await this.personalRepository.find({ + where: { + child3Dna: nodeId, + createdAt: + startDate && endDate + ? Between(new Date(startDate), new Date(endDate)) + : Not(IsNull()), + }, + }); + personal = await Promise.all( + personal.map(async (p, idx) => { + const assigns = await this.assignRepository.find({ + where: { personal_id: p.personal_id }, + }); + const no = idx + 1; + return { + no: no, + fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, + positionName: p.positionName, + organization: p.organization, + probation_status: p.probation_status, + idcard: p.idcard, + assigns: assigns, + }; + }) + ); + break; + } + case 4: { + personal = await this.personalRepository.find({ + where: { + child4Dna: nodeId, + createdAt: + startDate && endDate + ? Between(new Date(startDate), new Date(endDate)) + : Not(IsNull()), + }, + }); + personal = await Promise.all( + personal.map(async (p, idx) => { + const assigns = await this.assignRepository.find({ + where: { personal_id: p.personal_id }, + }); + const no = idx + 1; + return { + no: no, + fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, + positionName: p.positionName, + organization: p.organization, + probation_status: p.probation_status, + idcard: p.idcard, + assigns: assigns, + }; + }) + ); + break; + } + default: { + personal = await this.personalRepository.find({}); + personal = await Promise.all( + personal.map(async (p, idx) => { + const assigns = await this.assignRepository.find({ + where: { personal_id: p.personal_id }, + }); + const no = idx + 1; + return { + no: no, + fullName: `${p.prefixName}${p.firstName} ${p.lastName}`, + positionName: p.positionName, + organization: p.organization, + probation_status: p.probation_status, + idcard: p.idcard, + assigns: assigns, + }; + }) + ); + } + } - @Get("report3") - public async report3(@Request() req: RequestWithUser, @Query("nodeId") nodeId?: string, @Query("node") node?: string, @Query("startDate") startDate?: Date, @Query("endDate") endDate?: Date) { - interface Result { - [rootDnaId: string]: { - rootName: string - status1: number - status2: number - status3: number - status4: number - status5: number - status6: number - status7: number - } - } + result = await Promise.all( + personal.flatMap((x) => + (x.assigns.length > 0 + ? x.assigns + : [{ id: null, date_start: null, date_finish: null }] + ).map(async (assign) => { + let accExam: string = ""; + let dateAppoint: Date | any = null; + await new CallAPI() + .GetData(req, `/placement/exam-probation/${x.idcard}`) + .then(async (x) => { + accExam = x.examName; + dateAppoint = x.dateAppoint; + }) + .catch((errr) => {}); - const rootNode = await new CallAPI().PostData(req, "/org/find/node-all", { nodeId: nodeId, node: node }).catch(error => { - console.error("Error calling API:", error) - }) - const rootNodeTrue = rootNode["isRootTrue"] - const rootNodeFalse = rootNode["isRootFalse"] + const evaluateComman = await this.evaluateCommanderRepository.findOne( + { + where: { assign_id: assign.id ?? "" }, + } + ); - let whereRootTrue = rootNodeTrue && rootNodeTrue.rootDnaId ? { rootDna: rootNodeTrue.rootDnaId } : {} - let listsRootTrue = - rootNodeTrue && rootNodeTrue.rootDnaId - ? await this.personalRepository.find({ - where: { - ...whereRootTrue, - createdAt: startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : undefined, - }, - }) - : [] + return { + no: Extension.ToThaiNumber(x.no.toString()), + accExam: accExam, + fullName: x.fullName, + positionName: x.positionName, + organization: x.organization, + dateAppoint: dateAppoint + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(dateAppoint)) + : "", + dateStart: + x.assigns.length > 0 && assign.date_start != null + ? Extension.ToThaiNumber( + Extension.ToThaiFullDate2(assign.date_start) + ) + : "", + dateFinish: + x.assigns.length > 0 && assign.date_finish != null + ? Extension.ToThaiNumber( + Extension.ToThaiFullDate2(assign.date_finish) + ) + : "", + day: + x.assigns.length > 0 && + assign.date_start != null && + assign.date_finish != null + ? Extension.ToThaiNumber( + `${Math.ceil((new Date(assign.date_finish).getTime() - new Date(assign.date_start).getTime()) / (1000 * 60 * 60 * 24))} วัน` + ) + : "", + status: x.probation_status + ? Extension.probationStatus(x.probation_status) + : "", + orientation: + evaluateComman && evaluateComman?.orientation == 1 ? "☑" : "☐", + learning: + evaluateComman && evaluateComman?.self_learning == 1 ? "☑" : "☐", + seminar: + evaluateComman && evaluateComman?.training_seminar == 1 + ? "☑" + : "☐", + other: + evaluateComman && evaluateComman?.other_training == 1 + ? "☑" + : "☐", + }; + }) + ) + ); - let rootDnaIds = rootNodeFalse.map((node: any) => node.rootDnaId) - let listsRootFalse = - rootDnaIds && rootDnaIds.length - ? await this.personalRepository.find({ - where: { - rootDna: In(rootDnaIds), - createdAt: startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : undefined, - }, - }) - : [] + return new HttpSuccess({ + template: "placementProbation02", + reportName: "xlsx-report", + data: { + date: `ตั้งแต่${Extension.ToThaiNumber(Extension.ToThaiNoprefixDate2(startDate ?? new Date()))} ถึง ${Extension.ToThaiNumber(Extension.ToThaiNoprefixDate2(endDate ?? new Date()))}`, + dateCurrent: `ณ ${Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date()))}`, + data: result, + }, + }); + } - let resultTrue: Result = {} - let resultFalse: Result = {} + @Get("report3") + public async report3( + @Request() req: RequestWithUser, + @Query("nodeId") nodeId?: string, + @Query("node") node?: string, + @Query("startDate") startDate?: Date, + @Query("endDate") endDate?: Date + ) { + interface Result { + [rootDnaId: string]: { + rootName: string; + status1: number; + status2: number; + status3: number; + status4: number; + status5: number; + status6: number; + status7: number; + }; + } - listsRootTrue.forEach(item => { - let rootDnaId = item.rootDna - let status = item.probation_status - let rootName = item.orgRootName + const rootNode = await new CallAPI() + .PostData(req, "/org/find/node-all", { nodeId: nodeId, node: node }) + .catch((error) => { + console.error("Error calling API:", error); + }); + const rootNodeTrue = rootNode["isRootTrue"]; + const rootNodeFalse = rootNode["isRootFalse"]; - if (!resultTrue[rootDnaId]) { - resultTrue[rootDnaId] = { - rootName: rootName, - status1: 0, - status2: 0, - status3: 0, - status4: 0, - status5: 0, - status6: 0, - status7: 0, - } - } + let whereRootTrue = + rootNodeTrue && rootNodeTrue.rootDnaId + ? { rootDna: rootNodeTrue.rootDnaId } + : {}; + let listsRootTrue = + rootNodeTrue && rootNodeTrue.rootDnaId + ? await this.personalRepository.find({ + where: { + ...whereRootTrue, + createdAt: + startDate && endDate + ? Between(new Date(startDate), new Date(endDate)) + : undefined, + }, + }) + : []; - if (status >= 1 && status <= 7) { - ;(resultTrue[rootDnaId] as { [key: string]: any })[`status${status}`]++ - } - }) - listsRootFalse.forEach(item => { - let rootDnaId = item.rootDna - let status = item.probation_status - let rootName = item.orgRootName + let rootDnaIds = rootNodeFalse.map((node: any) => node.rootDnaId); + let listsRootFalse = + rootDnaIds && rootDnaIds.length + ? await this.personalRepository.find({ + where: { + rootDna: In(rootDnaIds), + createdAt: + startDate && endDate + ? Between(new Date(startDate), new Date(endDate)) + : undefined, + }, + }) + : []; - if (!resultFalse[rootDnaId]) { - resultFalse[rootDnaId] = { - rootName: rootName, - status1: 0, - status2: 0, - status3: 0, - status4: 0, - status5: 0, - status6: 0, - status7: 0, - } - } + let resultTrue: Result = {}; + let resultFalse: Result = {}; - if (status >= 1 && status <= 7) { - ;(resultFalse[rootDnaId] as { [key: string]: any })[`status${status}`]++ - } - }) - const resultTruePass = Object.values(resultTrue).reduce((sum, { status2 }) => sum + status2, 0) - const resultTrueExtand = Object.values(resultTrue).reduce((sum, { status7 }) => sum + status7, 0) - const resultTrueSuspension = "-" - const resultTrueChangePos = Object.values(resultTrue).reduce((sum, { status4 }) => sum + status4, 0) - const resultTrueResign = Object.values(resultTrue).reduce((sum, { status5 }) => sum + status5, 0) - const resultTrueDeceased = Object.values(resultTrue).reduce((sum, { status6 }) => sum + status6, 0) - const resultTrueNotPass = Object.values(resultTrue).reduce((sum, { status3 }) => sum + status3, 0) - const resultFalsePass = Object.values(resultFalse).reduce((sum, { status2 }) => sum + status2, 0) - const resultFalseExtand = Object.values(resultFalse).reduce((sum, { status7 }) => sum + status7, 0) - const resultFalseSuspension = "-" - const resultFalseChangePos = Object.values(resultFalse).reduce((sum, { status4 }) => sum + status4, 0) - const resultFalseResign = Object.values(resultFalse).reduce((sum, { status5 }) => sum + status5, 0) - const resultFalseDeceased = Object.values(resultFalse).reduce((sum, { status6 }) => sum + status6, 0) - const resultFalseNotPass = Object.values(resultFalse).reduce((sum, { status3 }) => sum + status3, 0) - const sumPass = Object.values(resultTrue).reduce((sum, { status2 }) => sum + status2, 0) + Object.values(resultFalse).reduce((sum, { status2 }) => sum + status2, 0) - const sumExtand = Object.values(resultTrue).reduce((sum, { status7 }) => sum + status7, 0) + Object.values(resultFalse).reduce((sum, { status7 }) => sum + status7, 0) - const sumSuspension = "-" - const sumChangePos = Object.values(resultTrue).reduce((sum, { status4 }) => sum + status4, 0) + Object.values(resultFalse).reduce((sum, { status4 }) => sum + status4, 0) - const sumResign = Object.values(resultTrue).reduce((sum, { status5 }) => sum + status5, 0) + Object.values(resultFalse).reduce((sum, { status5 }) => sum + status5, 0) - const sumDeceased = Object.values(resultTrue).reduce((sum, { status6 }) => sum + status6, 0) + Object.values(resultFalse).reduce((sum, { status6 }) => sum + status6, 0) - const sumNotPass = Object.values(resultTrue).reduce((sum, { status3 }) => sum + status3, 0) + Object.values(resultFalse).reduce((sum, { status3 }) => sum + status3, 0) - const sumResultTrue = Object.values(resultTrue).reduce((total, { status2, status7, status4, status5, status6, status3 }) => { - return total + status2 + status7 + status4 + status5 + status6 + status3 - }, 0) - const sumResultFalse = Object.values(resultFalse).reduce((total, { status2, status7, status4, status5, status6, status3 }) => { - return total + status2 + status7 + status4 + status5 + status6 + status3 - }, 0) - const sumAll = sumPass + sumExtand + sumChangePos + sumResign + sumDeceased + sumNotPass - const nowDate = Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())) - const formattedData = { - topic: "หน่วยงานระดับสำนักหรือเทียบเท่า", - dateNow: nowDate, - accExam: "", - dateStart: startDate ? Extension.ToThaiNumber(Extension.ToThaiNoprefixDate(startDate)) : "", - dateEnd: endDate ? Extension.ToThaiNumber(Extension.ToThaiNoprefixDate(endDate)) : "", - resultTrueProbation: Object.keys(resultTrue).map((rootDnaId, index) => { - const { status2, status7, status4, status5, status6, status3, rootName } = resultTrue[rootDnaId] - const sum = status2 + status7 + status4 + status5 + status6 + status3 - return { - rowNo: (index + 1).toString(), - rootName: rootName.toString(), - pass: status2.toString(), - extand: status7.toString(), - suspension: "-", - changePos: status4.toString(), - resign: status5.toString(), - deceased: status6.toString(), - notPass: status3.toString(), - total: sum.toString(), - } - }), - resultTruePass: resultTruePass.toString(), - resultTrueExtand: resultTrueExtand.toString(), - resultTrueSuspension: "-", - resultTrueChangePos: resultTrueChangePos.toString(), - resultTrueResign: resultTrueResign.toString(), - resultTrueDeceased: resultTrueDeceased.toString(), - resultTrueNotPass: resultTrueNotPass.toString(), - topic2: "หน่วยงานระดับสำนักงานเขต", - resultFalseProbation: Object.keys(resultFalse).map((rootDnaId, index) => { - const { status2, status7, status4, status5, status6, status3, rootName } = resultFalse[rootDnaId] - const sum = status2 + status7 + status4 + status5 + status6 + status3 - return { - rowNo: (index + 1).toString(), - rootName: rootName.toString(), - pass: status2.toString(), - extand: status7.toString(), - suspension: "-", - changePos: status4.toString(), - resign: status5.toString(), - deceased: status6.toString(), - notPass: status3.toString(), - total: sum.toString(), - } - }), - resultFalsePass: resultFalsePass.toString(), - resultFalseExtand: resultFalseExtand.toString(), - resultFalseSuspension: "-", - resultFalseChangePos: resultFalseChangePos.toString(), - resultFalseResign: resultFalseResign.toString(), - resultFalseDeceased: resultFalseDeceased.toString(), - resultFalseNotPass: resultFalseNotPass.toString(), - sumPass: sumPass.toString(), - sumExtand: sumExtand.toString(), - sumSuspension: "-", - sumChangePos: sumChangePos.toString(), - sumResign: sumResign.toString(), - sumDeceased: sumDeceased.toString(), - sumNotPass: sumNotPass.toString(), - sumResultTrue: sumResultTrue.toString(), - sumResultFalse: sumResultFalse.toString(), - sumAll: sumAll.toString(), - } - return new HttpSuccess({ - template: "placementProbation03", - reportName: "xlsx-report", - data: formattedData, - }) - } + listsRootTrue.forEach((item) => { + let rootDnaId = item.rootDna; + let status = item.probation_status; + let rootName = item.orgRootName; + + if (!resultTrue[rootDnaId]) { + resultTrue[rootDnaId] = { + rootName: rootName, + status1: 0, + status2: 0, + status3: 0, + status4: 0, + status5: 0, + status6: 0, + status7: 0, + }; + } + + if (status >= 1 && status <= 7) { + (resultTrue[rootDnaId] as { [key: string]: any })[`status${status}`]++; + } + }); + listsRootFalse.forEach((item) => { + let rootDnaId = item.rootDna; + let status = item.probation_status; + let rootName = item.orgRootName; + + if (!resultFalse[rootDnaId]) { + resultFalse[rootDnaId] = { + rootName: rootName, + status1: 0, + status2: 0, + status3: 0, + status4: 0, + status5: 0, + status6: 0, + status7: 0, + }; + } + + if (status >= 1 && status <= 7) { + (resultFalse[rootDnaId] as { [key: string]: any })[`status${status}`]++; + } + }); + const resultTruePass = Object.values(resultTrue).reduce( + (sum, { status2 }) => sum + status2, + 0 + ); + const resultTrueExtand = Object.values(resultTrue).reduce( + (sum, { status7 }) => sum + status7, + 0 + ); + const resultTrueSuspension = "-"; + const resultTrueChangePos = Object.values(resultTrue).reduce( + (sum, { status4 }) => sum + status4, + 0 + ); + const resultTrueResign = Object.values(resultTrue).reduce( + (sum, { status5 }) => sum + status5, + 0 + ); + const resultTrueDeceased = Object.values(resultTrue).reduce( + (sum, { status6 }) => sum + status6, + 0 + ); + const resultTrueNotPass = Object.values(resultTrue).reduce( + (sum, { status3 }) => sum + status3, + 0 + ); + const resultFalsePass = Object.values(resultFalse).reduce( + (sum, { status2 }) => sum + status2, + 0 + ); + const resultFalseExtand = Object.values(resultFalse).reduce( + (sum, { status7 }) => sum + status7, + 0 + ); + const resultFalseSuspension = "-"; + const resultFalseChangePos = Object.values(resultFalse).reduce( + (sum, { status4 }) => sum + status4, + 0 + ); + const resultFalseResign = Object.values(resultFalse).reduce( + (sum, { status5 }) => sum + status5, + 0 + ); + const resultFalseDeceased = Object.values(resultFalse).reduce( + (sum, { status6 }) => sum + status6, + 0 + ); + const resultFalseNotPass = Object.values(resultFalse).reduce( + (sum, { status3 }) => sum + status3, + 0 + ); + const sumPass = + Object.values(resultTrue).reduce((sum, { status2 }) => sum + status2, 0) + + Object.values(resultFalse).reduce((sum, { status2 }) => sum + status2, 0); + const sumExtand = + Object.values(resultTrue).reduce((sum, { status7 }) => sum + status7, 0) + + Object.values(resultFalse).reduce((sum, { status7 }) => sum + status7, 0); + const sumSuspension = "-"; + const sumChangePos = + Object.values(resultTrue).reduce((sum, { status4 }) => sum + status4, 0) + + Object.values(resultFalse).reduce((sum, { status4 }) => sum + status4, 0); + const sumResign = + Object.values(resultTrue).reduce((sum, { status5 }) => sum + status5, 0) + + Object.values(resultFalse).reduce((sum, { status5 }) => sum + status5, 0); + const sumDeceased = + Object.values(resultTrue).reduce((sum, { status6 }) => sum + status6, 0) + + Object.values(resultFalse).reduce((sum, { status6 }) => sum + status6, 0); + const sumNotPass = + Object.values(resultTrue).reduce((sum, { status3 }) => sum + status3, 0) + + Object.values(resultFalse).reduce((sum, { status3 }) => sum + status3, 0); + const sumResultTrue = Object.values(resultTrue).reduce( + (total, { status2, status7, status4, status5, status6, status3 }) => { + return ( + total + status2 + status7 + status4 + status5 + status6 + status3 + ); + }, + 0 + ); + const sumResultFalse = Object.values(resultFalse).reduce( + (total, { status2, status7, status4, status5, status6, status3 }) => { + return ( + total + status2 + status7 + status4 + status5 + status6 + status3 + ); + }, + 0 + ); + const sumAll = + sumPass + sumExtand + sumChangePos + sumResign + sumDeceased + sumNotPass; + const nowDate = Extension.ToThaiNumber( + Extension.ToThaiShortDate(new Date()) + ); + const formattedData = { + topic: "หน่วยงานระดับสำนักหรือเทียบเท่า", + dateNow: nowDate, + accExam: "", + dateStart: startDate + ? Extension.ToThaiNumber(Extension.ToThaiNoprefixDate(startDate)) + : "", + dateEnd: endDate + ? Extension.ToThaiNumber(Extension.ToThaiNoprefixDate(endDate)) + : "", + resultTrueProbation: Object.keys(resultTrue).map((rootDnaId, index) => { + const { + status2, + status7, + status4, + status5, + status6, + status3, + rootName, + } = resultTrue[rootDnaId]; + const sum = status2 + status7 + status4 + status5 + status6 + status3; + return { + rowNo: (index + 1).toString(), + rootName: rootName.toString(), + pass: status2.toString(), + extand: status7.toString(), + suspension: "-", + changePos: status4.toString(), + resign: status5.toString(), + deceased: status6.toString(), + notPass: status3.toString(), + total: sum.toString(), + }; + }), + resultTruePass: resultTruePass.toString(), + resultTrueExtand: resultTrueExtand.toString(), + resultTrueSuspension: "-", + resultTrueChangePos: resultTrueChangePos.toString(), + resultTrueResign: resultTrueResign.toString(), + resultTrueDeceased: resultTrueDeceased.toString(), + resultTrueNotPass: resultTrueNotPass.toString(), + topic2: "หน่วยงานระดับสำนักงานเขต", + resultFalseProbation: Object.keys(resultFalse).map((rootDnaId, index) => { + const { + status2, + status7, + status4, + status5, + status6, + status3, + rootName, + } = resultFalse[rootDnaId]; + const sum = status2 + status7 + status4 + status5 + status6 + status3; + return { + rowNo: (index + 1).toString(), + rootName: rootName.toString(), + pass: status2.toString(), + extand: status7.toString(), + suspension: "-", + changePos: status4.toString(), + resign: status5.toString(), + deceased: status6.toString(), + notPass: status3.toString(), + total: sum.toString(), + }; + }), + resultFalsePass: resultFalsePass.toString(), + resultFalseExtand: resultFalseExtand.toString(), + resultFalseSuspension: "-", + resultFalseChangePos: resultFalseChangePos.toString(), + resultFalseResign: resultFalseResign.toString(), + resultFalseDeceased: resultFalseDeceased.toString(), + resultFalseNotPass: resultFalseNotPass.toString(), + sumPass: sumPass.toString(), + sumExtand: sumExtand.toString(), + sumSuspension: "-", + sumChangePos: sumChangePos.toString(), + sumResign: sumResign.toString(), + sumDeceased: sumDeceased.toString(), + sumNotPass: sumNotPass.toString(), + sumResultTrue: sumResultTrue.toString(), + sumResultFalse: sumResultFalse.toString(), + sumAll: sumAll.toString(), + }; + return new HttpSuccess({ + template: "placementProbation03", + reportName: "xlsx-report", + data: formattedData, + }); + } }