import { Controller, Route, Security, Tags, Body, Request, SuccessResponse, 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 } 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, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", ) 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) { const evaluate = await this.evaluateChairmanRepository.findOne({ where: { assign_id }, }); const result = await this.evaluateResultRepository.findOne({ where: { assign_id }, }); 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)); 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 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, 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?: string, @Query("startDate") startDate?: Date, @Query("endDate") endDate?: Date, ) { return new HttpSuccess({ template: "placementProbation02", reportName: "xlsx-report", data: "", }); } @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, }); } }