From 5267478dcec2f968f9fe29856095e498bc87486e Mon Sep 17 00:00:00 2001 From: "DESKTOP-2S5P7D1\\Windows 10" Date: Wed, 5 Feb 2025 15:37:47 +0700 Subject: [PATCH] add dna --- src/controllers/PersonalController.ts | 6 + src/controllers/ReportController.ts | 4068 ++++++++--------- src/entities/Personal.ts | 21 + .../1738744610414-updatepersonadddna.ts | 22 + 4 files changed, 1982 insertions(+), 2135 deletions(-) create mode 100644 src/migration/1738744610414-updatepersonadddna.ts diff --git a/src/controllers/PersonalController.ts b/src/controllers/PersonalController.ts index c6b54c3..e8ddb63 100644 --- a/src/controllers/PersonalController.ts +++ b/src/controllers/PersonalController.ts @@ -69,6 +69,12 @@ export class PersonalController extends Controller { personalData.child3 = requestBody.child3 personalData.child4 = requestBody.child4 + personalData.rootDna = requestBody.rootDna + personalData.child1Dna = requestBody.child1Dna + personalData.child2Dna = requestBody.child2Dna + personalData.child3Dna = requestBody.child3Dna + personalData.child4Dna = requestBody.child4Dna + const before = null const personal = await this.personalRepository.save(personalData, { data: request, diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 395df45..3ac005c 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1,2141 +1,1939 @@ -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" @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; - commandAffectDate: Date | null; - commandNo: string | null; - commandId: string | null; - commandYear: number; - templateDoc: string | null; - amount: Double | null; - amountSpecial?: Double | null; - positionSalaryAmount: Double | null; - mouthSalaryAmount: Double | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; - }[]; - }, - ) { - await new CallAPI() - .PostData(request, "/org/command/excexute/salary-probation", { - data: body.refIds.map((v) => ({ - profileId: v.refId, - commandId: v.commandId, - date: v.commandAffectDate, - refCommandNo: `${v.commandNo}/${Extension.ToThaiYear(v.commandYear)}`, - salaryRef: v.templateDoc, - amount: v.amount, - amountSpecial: v.amountSpecial, - positionSalaryAmount: v.positionSalaryAmount, - mouthSalaryAmount: v.mouthSalaryAmount, - refCommandCode: v.refCommandCode, - refCommandName: v.refCommandName, - })), - }) - .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; - commandAffectDate: Date | null; - commandNo: string | null; - commandId: string | null; - commandYear: number; - templateDoc: string | null; - amount: Double | null; - amountSpecial?: Double | null; - positionSalaryAmount: Double | null; - mouthSalaryAmount: Double | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; - }[]; - }, - ) { - await new CallAPI() - .PostData(request, "/org/command/excexute/salary-probation-leave", { - data: body.refIds.map((v) => ({ - profileId: v.refId, - commandId: v.commandId, - date: v.commandAffectDate, - refCommandNo: `${v.commandNo}/${Extension.ToThaiYear(v.commandYear)}`, - salaryRef: v.templateDoc, - amount: v.amount, - positionSalaryAmount: v.positionSalaryAmount, - mouthSalaryAmount: v.mouthSalaryAmount, - isGovernment: false, - refCommandCode: v.refCommandCode, - refCommandName: v.refCommandName, - })), - }) - .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; - commandNo: string | null; - commandId?: string | null; - commandYear: number; - templateDoc: string | null; - amount: Double | null; - amountSpecial?: Double | null; - positionSalaryAmount: Double | null; - mouthSalaryAmount: Double | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: 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(); - } - - @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); - } - - @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 { - [rootId: string]: { - rootName: string; - status1: number; - status2: number; - status3: number; - status4: number; - status5: number; - status6: number; - status7: number; - }; - } - - 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"]; - - let whereRootTrue = rootNodeTrue && rootNodeTrue.rootId ? { root: rootNodeTrue.rootId } : {}; - let listsRootTrue = - rootNodeTrue && rootNodeTrue.rootId - ? await this.personalRepository.find({ - where: { - ...whereRootTrue, - createdAt: - startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : undefined, - }, - }) - : []; - - let rootIds = rootNodeFalse.map((node: any) => node.rootId); - let listsRootFalse = - rootIds && rootIds.length - ? await this.personalRepository.find({ - where: { - root: In(rootIds), - createdAt: - startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : undefined, - }, - }) - : []; - - let resultTrue: Result = {}; - let resultFalse: Result = {}; - - listsRootTrue.forEach((item) => { - let rootId = item.root; - let status = item.probation_status; - let rootName = item.orgRootName; - - if (!resultTrue[rootId]) { - resultTrue[rootId] = { - rootName: rootName, - status1: 0, - status2: 0, - status3: 0, - status4: 0, - status5: 0, - status6: 0, - status7: 0, - }; - } - - if (status >= 1 && status <= 7) { - (resultTrue[rootId] as { [key: string]: any })[`status${status}`]++; - } - }); - listsRootFalse.forEach((item) => { - let rootId = item.root; - let status = item.probation_status; - let rootName = item.orgRootName; - - if (!resultFalse[rootId]) { - resultFalse[rootId] = { - rootName: rootName, - status1: 0, - status2: 0, - status3: 0, - status4: 0, - status5: 0, - status6: 0, - status7: 0, - }; - } - - if (status >= 1 && status <= 7) { - (resultFalse[rootId] 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((rootId, index) => { - const { status2, status7, status4, status5, status6, status3, rootName } = - resultTrue[rootId]; - 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((rootId, index) => { - const { status2, status7, status4, status5, status6, status3, rootName } = - resultFalse[rootId]; - 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, - }); - } - - @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: { - root: 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: { - child1: 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: { - child2: 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: { - child3: 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: { - child4: 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, - }; - }), - ); - } - } - - 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 evaluateComman = await this.evaluateCommanderRepository.findOne({ - where: { assign_id: assign.id ?? "" }, - }); - - 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 ? "☑" : "☐", - }; - }), - ), - ); - - 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("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 { - [rootId: string]: { - rootName: string; - status1: number; - status2: number; - status3: number; - status4: number; - status5: number; - status6: number; - status7: number; - }; - } - - 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"]; - - let whereRootTrue = rootNodeTrue && rootNodeTrue.rootId ? { root: rootNodeTrue.rootId } : {}; - let listsRootTrue = - rootNodeTrue && rootNodeTrue.rootId - ? await this.personalRepository.find({ - where: { - ...whereRootTrue, - createdAt: - startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : undefined, - }, - }) - : []; - - let rootIds = rootNodeFalse.map((node: any) => node.rootId); - let listsRootFalse = - rootIds && rootIds.length - ? await this.personalRepository.find({ - where: { - root: In(rootIds), - createdAt: - startDate && endDate ? Between(new Date(startDate), new Date(endDate)) : undefined, - }, - }) - : []; - - let resultTrue: Result = {}; - let resultFalse: Result = {}; - - listsRootTrue.forEach((item) => { - let rootId = item.root; - let status = item.probation_status; - let rootName = item.orgRootName; - - if (!resultTrue[rootId]) { - resultTrue[rootId] = { - rootName: rootName, - status1: 0, - status2: 0, - status3: 0, - status4: 0, - status5: 0, - status6: 0, - status7: 0, - }; - } - - if (status >= 1 && status <= 7) { - (resultTrue[rootId] as { [key: string]: any })[`status${status}`]++; - } - }); - listsRootFalse.forEach((item) => { - let rootId = item.root; - let status = item.probation_status; - let rootName = item.orgRootName; - - if (!resultFalse[rootId]) { - resultFalse[rootId] = { - rootName: rootName, - status1: 0, - status2: 0, - status3: 0, - status4: 0, - status5: 0, - status6: 0, - status7: 0, - }; - } - - if (status >= 1 && status <= 7) { - (resultFalse[rootId] 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((rootId, index) => { - const { status2, status7, status4, status5, status6, status3, rootName } = - resultTrue[rootId]; - 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((rootId, index) => { - const { status2, status7, status4, status5, status6, status3, rootName } = - resultFalse[rootId]; - 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, - }); - } + 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 + commandAffectDate: Date | null + commandNo: string | null + commandId: string | null + commandYear: number + templateDoc: string | null + amount: Double | null + amountSpecial?: Double | null + positionSalaryAmount: Double | null + mouthSalaryAmount: Double | null + mpCee?: string | null + refCommandCode?: string | null + refCommandName?: string | null + }[] + } + ) { + await new CallAPI() + .PostData(request, "/org/command/excexute/salary-probation", { + data: body.refIds.map(v => ({ + profileId: v.refId, + commandId: v.commandId, + date: v.commandAffectDate, + refCommandNo: `${v.commandNo}/${Extension.ToThaiYear(v.commandYear)}`, + salaryRef: v.templateDoc, + amount: v.amount, + amountSpecial: v.amountSpecial, + positionSalaryAmount: v.positionSalaryAmount, + mouthSalaryAmount: v.mouthSalaryAmount, + refCommandCode: v.refCommandCode, + refCommandName: v.refCommandName, + })), + }) + .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 + commandAffectDate: Date | null + commandNo: string | null + commandId: string | null + commandYear: number + templateDoc: string | null + amount: Double | null + amountSpecial?: Double | null + positionSalaryAmount: Double | null + mouthSalaryAmount: Double | null + mpCee?: string | null + refCommandCode?: string | null + refCommandName?: string | null + }[] + } + ) { + await new CallAPI() + .PostData(request, "/org/command/excexute/salary-probation-leave", { + data: body.refIds.map(v => ({ + profileId: v.refId, + commandId: v.commandId, + date: v.commandAffectDate, + refCommandNo: `${v.commandNo}/${Extension.ToThaiYear(v.commandYear)}`, + salaryRef: v.templateDoc, + amount: v.amount, + positionSalaryAmount: v.positionSalaryAmount, + mouthSalaryAmount: v.mouthSalaryAmount, + isGovernment: false, + refCommandCode: v.refCommandCode, + refCommandName: v.refCommandName, + })), + }) + .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 + commandNo: string | null + commandId?: string | null + commandYear: number + templateDoc: string | null + amount: Double | null + amountSpecial?: Double | null + positionSalaryAmount: Double | null + mouthSalaryAmount: Double | null + mpCee?: string | null + refCommandCode?: string | null + refCommandName?: 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() + } + + @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) + } + + @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 + } + } + + 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"] + + 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, + }, + }) + : [] + + 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, + }, + }) + : [] + + let resultTrue: Result = {} + let resultFalse: Result = {} + + 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, + 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, + }) + } + + @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, + } + }) + ) + } + } + + 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 evaluateComman = await this.evaluateCommanderRepository.findOne({ + where: { assign_id: assign.id ?? "" }, + }) + + 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 ? "☑" : "☐", + } + }) + ) + ) + + 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("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 + } + } + + 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"] + + 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, + }, + }) + : [] + + 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, + }, + }) + : [] + + let resultTrue: Result = {} + let resultFalse: Result = {} + + 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, + }) + } } diff --git a/src/entities/Personal.ts b/src/entities/Personal.ts index 383e183..6e3217e 100644 --- a/src/entities/Personal.ts +++ b/src/entities/Personal.ts @@ -118,6 +118,21 @@ export class Personal extends EntityBase { @Column({ nullable: true, comment: "id หน่วยงาน child4", default: null }) child4: string + @Column({ nullable: true, comment: "id หน่วยงาน root", default: null }) + rootDna: string + + @Column({ nullable: true, comment: "id หน่วยงาน child1", default: null }) + child1Dna: string + + @Column({ nullable: true, comment: "id หน่วยงาน child2", default: null }) + child2Dna: string + + @Column({ nullable: true, comment: "id หน่วยงาน child3", default: null }) + child3Dna: string + + @Column({ nullable: true, comment: "id หน่วยงาน child4", default: null }) + child4Dna: string + @OneToMany(() => Assign, (assign: Assign) => assign.personal_id) @JoinColumn({ name: "id" }) assign: Assign[] @@ -204,6 +219,12 @@ export class PostPersonal { child2?: string | null child3?: string | null child4?: string | null + + rootDna?: string | null + child1Dna?: string | null + child2Dna?: string | null + child3Dna?: string | null + child4Dna?: string | null } export type UpdatePersonal = Partial diff --git a/src/migration/1738744610414-updatepersonadddna.ts b/src/migration/1738744610414-updatepersonadddna.ts new file mode 100644 index 0000000..d334d4a --- /dev/null +++ b/src/migration/1738744610414-updatepersonadddna.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Updatepersonadddna1738744610414 implements MigrationInterface { + name = 'Updatepersonadddna1738744610414' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`rootDna\` varchar(255) NULL COMMENT 'id หน่วยงาน root'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child1Dna\` varchar(255) NULL COMMENT 'id หน่วยงาน child1'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child2Dna\` varchar(255) NULL COMMENT 'id หน่วยงาน child2'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child3Dna\` varchar(255) NULL COMMENT 'id หน่วยงาน child3'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child4Dna\` varchar(255) NULL COMMENT 'id หน่วยงาน child4'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child4Dna\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child3Dna\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child2Dna\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child1Dna\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`rootDna\``); + } + +}