From fd42120b9d8fd801c338d8f3cc2b879f77f57607 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 25 Oct 2024 12:35:47 +0700 Subject: [PATCH] updated appoint & sen data to command --- src/controllers/PersonalController.ts | 326 +- src/controllers/ReportController.ts | 2610 +++++++++-------- src/entities/AppointDirector.ts | 4 +- src/entities/Personal.ts | 27 +- .../1729823259868-alterColumnAppoint.ts | 14 + .../1729832583096-addColumnPersonal.ts | 22 + 6 files changed, 1574 insertions(+), 1429 deletions(-) create mode 100644 src/migration/1729823259868-alterColumnAppoint.ts create mode 100644 src/migration/1729832583096-addColumnPersonal.ts diff --git a/src/controllers/PersonalController.ts b/src/controllers/PersonalController.ts index 8d9ea64..1fc0726 100644 --- a/src/controllers/PersonalController.ts +++ b/src/controllers/PersonalController.ts @@ -1,167 +1,209 @@ -import { Controller, Post, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Query } 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 { setLogDataDiff } from "../interfaces/utils" -import { Personal, PostPersonal } from "../entities/Personal" -import permission from "../interfaces/permission" -import { Assign } from "../entities/Assign" +import { + Controller, + Post, + Route, + Security, + Tags, + Body, + Request, + SuccessResponse, + Response, + Get, + Query, +} 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 { setLogDataDiff } from "../interfaces/utils"; +import { Personal, PostPersonal } from "../entities/Personal"; +import permission from "../interfaces/permission"; +import { Assign } from "../entities/Assign"; @Route("api/v1/probation/personal") @Tags("Personal") @Security("bearerAuth") -@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) export class PersonalController extends Controller { - private personalRepository = AppDataSource.getRepository(Personal) - private assignRepository = AppDataSource.getRepository(Assign) + private personalRepository = AppDataSource.getRepository(Personal); + private assignRepository = AppDataSource.getRepository(Assign); - /** - * API ข้อมูลบุคคลในระบบทดลองงาน - * - * @summary เพิ่มคนเข้าระบบทดลองงาน - * - */ - @Post("add") - async AddPersonal(@Body() requestBody: PostPersonal, @Request() request: RequestWithUser) { - await new permission().PermissionCreate(request, "SYS_PROBATION") + /** + * API ข้อมูลบุคคลในระบบทดลองงาน + * + * @summary เพิ่มคนเข้าระบบทดลองงาน + * + */ + @Post("add") + async AddPersonal(@Body() requestBody: PostPersonal, @Request() request: RequestWithUser) { + await new permission().PermissionCreate(request, "SYS_PROBATION"); - const checkPersonal: number = await this.personalRepository.count({ - where: { personal_id: requestBody.id }, - }) - if (checkPersonal > 0) { - throw new HttpError(HttpStatusCode.BAD_REQUEST, "ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว") - } + const checkPersonal: number = await this.personalRepository.count({ + where: { personal_id: requestBody.id }, + }); + if (checkPersonal > 0) { + throw new HttpError(HttpStatusCode.BAD_REQUEST, "ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว"); + } - let organization = await (requestBody.orgChild4Name ? requestBody.orgChild4Name + "/" : "") - organization += await (requestBody.orgChild3Name ? requestBody.orgChild3Name + "/" : "") - organization += await (requestBody.orgChild2Name ? requestBody.orgChild2Name + "/" : "") - organization += await (requestBody.orgChild1Name ? requestBody.orgChild1Name + "/" : "") - organization += await (requestBody.orgRootName ? requestBody.orgRootName : "") + let organization = await (requestBody.orgChild4Name ? requestBody.orgChild4Name + "/" : ""); + organization += await (requestBody.orgChild3Name ? requestBody.orgChild3Name + "/" : ""); + organization += await (requestBody.orgChild2Name ? requestBody.orgChild2Name + "/" : ""); + organization += await (requestBody.orgChild1Name ? requestBody.orgChild1Name + "/" : ""); + organization += await (requestBody.orgRootName ? requestBody.orgRootName : ""); - const personalData = Object.assign(new Personal()) - personalData.personal_id = requestBody.id - personalData.order_number = requestBody.order_number ? requestBody.order_number : "" - personalData.probation_status = 1 - personalData.createdUserId = request.user.sub - personalData.createdFullName = request.user.name - personalData.updateUserId = request.user.sub - personalData.updateFullName = request.user.name + const personalData = Object.assign(new Personal()); + personalData.personal_id = requestBody.id; + personalData.order_number = requestBody.order_number ? requestBody.order_number : ""; + personalData.probation_status = 1; + personalData.createdUserId = request.user.sub; + personalData.createdFullName = request.user.name; + personalData.updateUserId = request.user.sub; + personalData.updateFullName = request.user.name; - personalData.idcard = requestBody.idcard - personalData.prefixName = requestBody.prefix - personalData.firstName = requestBody.firstName - personalData.lastName = requestBody.lastName - personalData.isProbation = requestBody.isProbation ? 1 : 0 - personalData.positionLevelName = requestBody.posLevelName ? requestBody.posLevelName : "" - personalData.positionName = requestBody.position ? requestBody.position : "" - personalData.positionLineName = requestBody.posLineName - personalData.positionTypeName = requestBody.posTypeName - personalData.posNo = requestBody.posNo ? requestBody.posNo : "" - personalData.orgRootName = requestBody.orgRootName - personalData.organization = organization + personalData.idcard = requestBody.idcard; + personalData.prefixName = requestBody.prefix; + personalData.firstName = requestBody.firstName; + personalData.lastName = requestBody.lastName; + personalData.isProbation = requestBody.isProbation ? 1 : 0; + personalData.positionLevelName = requestBody.posLevelName ? requestBody.posLevelName : ""; + personalData.positionName = requestBody.position ? requestBody.position : ""; + personalData.positionLineName = requestBody.posLineName; + personalData.positionTypeName = requestBody.posTypeName; + personalData.posNo = requestBody.posNo ? requestBody.posNo : ""; + personalData.orgRootName = requestBody.orgRootName; + personalData.organization = organization; - const before = null - const personal = await this.personalRepository.save(personalData, { - data: request, - }) - setLogDataDiff(request, { before, after: personal }) + const before = null; + const personal = await this.personalRepository.save(personalData, { + data: request, + }); + setLogDataDiff(request, { before, after: personal }); - return new HttpSuccess() - } + return new HttpSuccess(); + } - /** - * API รายการบุคคลในระบบทดลองงาน - * - * @summary รายชื่อคนที่อยู่ในระบบทดลองงาน - * - */ - @Get("list") - async ListPersonal(@Query() status: string = "", @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Request() request: RequestWithUser) { - await new permission().PermissionList(request, "SYS_PROBATION") - const conditions: any = {} - if (status) { - conditions.probation_status = status - } + /** + * API รายการบุคคลในระบบทดลองงาน + * + * @summary รายชื่อคนที่อยู่ในระบบทดลองงาน + * + */ + @Get("list") + async ListPersonal( + @Query() status: string = "", + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Request() request: RequestWithUser, + ) { + await new permission().PermissionList(request, "SYS_PROBATION"); + const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION"); - const [lists, total] = await this.personalRepository.findAndCount({ - order: { createdAt: "DESC" }, - where: conditions, - skip: (page - 1) * pageSize, - take: pageSize, - }) + const conditions: any = {}; + if (status) { + conditions.probation_status = status; + } - if (!lists) { - throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้") - } + if (_data.root != undefined && _data.root != null && _data.root[0] != null) { + conditions.root = _data.root; + } - let result: any = [] + if (_data.child1 != undefined && _data.child1 != null && _data.child1[0] != null) { + conditions.child1 = _data.child1; + } - await Promise.all( - lists.map(async (item, index) => { - const probation_no = await this.assignRepository.count({ - where: { - personal_id: item.personal_id, - }, - }) + if (_data.child2 != undefined && _data.child2 != null && _data.child2[0] != null) { + conditions.child2 = _data.child2; + } - await result.push({ - personal_id: item.personal_id, - ordering: index + 1, - name: item.prefixName + item.firstName + " " + item.lastName, - idcard: item.idcard, - prefixName: item.prefixName, - firstName: item.firstName, - lastName: item.lastName, - position_line: item.positionName, - position_level: item.positionLevelName, - position_type: item.positionTypeName, - organization: item.organization, - probation_no: probation_no, - order_number: item.order_number, - probation_status: item.probation_status, - }) - }) - ) + if (_data.child3 != undefined && _data.child3 != null && _data.child3[0] != null) { + conditions.child3 = _data.child3; + } - return new HttpSuccess({ data: result, total: total }) - } + if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) { + conditions.child4 = _data.child4; + } - /** - * API ข้อมูลบุคคลในระบบทดลองงาน - * - * @summary ข้อมูลคนที่อยูาในระบบทดลองงาน - * - */ - @Get("") - async GetPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) { - let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION") - if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION") - const person = await this.personalRepository.findOne({ - where: { personal_id: personal_id }, - }) + const [lists, total] = await this.personalRepository.findAndCount({ + order: { createdAt: "DESC" }, + where: conditions, + skip: (page - 1) * pageSize, + take: pageSize, + }); - if (!person) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล") - } + if (!lists) { + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้"); + } - const probation_no = await this.assignRepository.count({ - where: { personal_id: person.personal_id }, - }) + let result: any = []; - const result = await { - personal_id: person.personal_id, - name: person.prefixName + person.firstName + " " + person.lastName, - position_line: person.positionName, - position_level: person.positionLevelName, - position_type: person.positionTypeName, - organization: person.organization, - probation_no: probation_no, - order_number: person.order_number, - probation_status: person.probation_status, - } + await Promise.all( + lists.map(async (item, index) => { + const probation_no = await this.assignRepository.count({ + where: { + personal_id: item.personal_id, + }, + }); - return new HttpSuccess(result) - } + await result.push({ + personal_id: item.personal_id, + ordering: index + 1, + name: item.prefixName + item.firstName + " " + item.lastName, + idcard: item.idcard, + prefixName: item.prefixName, + firstName: item.firstName, + lastName: item.lastName, + position_line: item.positionName, + position_level: item.positionLevelName, + position_type: item.positionTypeName, + organization: item.organization, + probation_no: probation_no, + order_number: item.order_number, + probation_status: item.probation_status, + }); + }), + ); + + return new HttpSuccess({ data: result, total: total }); + } + + /** + * API ข้อมูลบุคคลในระบบทดลองงาน + * + * @summary ข้อมูลคนที่อยูาในระบบทดลองงาน + * + */ + @Get("") + async GetPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) { + let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION"); + const person = await this.personalRepository.findOne({ + where: { personal_id: personal_id }, + }); + + if (!person) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล"); + } + + const probation_no = await this.assignRepository.count({ + where: { personal_id: person.personal_id }, + }); + + const result = await { + personal_id: person.personal_id, + name: person.prefixName + person.firstName + " " + person.lastName, + position_line: person.positionName, + position_level: person.positionLevelName, + position_type: person.positionTypeName, + organization: person.organization, + probation_no: probation_no, + order_number: person.order_number, + probation_status: person.probation_status, + }; + + return new HttpSuccess(result); + } } diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 9f9c356..ff1d382 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1,1281 +1,1341 @@ -import { Controller, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Query, Put, Post } 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 { Double, In } from "typeorm" -import Extension from "../interfaces/extension" -import { Appoint } from "../entities/Appoint" +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 { Double, In } from "typeorm"; +import Extension from "../interfaces/extension"; +import { Appoint } from "../entities/Appoint"; +import { AppointDirector } from "../entities/AppointDirector"; @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) - - /** - * 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, - } - - const achievements = await this.evaluateAchievementRepository.find({ - select: ["evaluate_expect_level", "evaluate_output_level"], - where: { evaluate_id: evaluate.id }, - }) - - if (!achievements) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") - } - - let achievement: any = [] - await Promise.all( - achievements.map(async element => { - const evaluate_expect_level = await { - 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 ? "/" : "", - } - - const evaluate_output_level = await { - 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 ? "/" : "", - } - - achievement.push({ - ...element, - evaluate_expect_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 experimentee = await { - ...experimenteeData, - name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, - PositionLevelName: experimenteeData.positionLevelName, - PositionLineName: experimenteeData.positionLineName, - Position: experimenteeData.positionName, - Department: "-", - OrganizationOrganization: experimenteeData.orgRootName, - Oc: experimenteeData.organization, - } - - 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 experimentee = await { - ...experimenteeData, - name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, - PositionLevelName: experimenteeData.positionLevelName, - PositionLineName: experimenteeData.positionLineName, - Position: experimenteeData.positionName, - Department: "-", - OrganizationOrganization: experimenteeData.orgRootName, - Oc: experimenteeData.organization, - } - - 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, - } - - 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 experimentee = await { - ...experimenteeData, - name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, - PositionLevelName: experimenteeData.positionLevelName, - PositionLineName: experimenteeData.positionLineName, - Position: experimenteeData.positionName, - Department: "-", - OrganizationOrganization: experimenteeData.orgRootName, - Oc: experimenteeData.organization, - } - - 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, - } - }) - ) - - 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 - positionSalaryAmount: Double | null - mouthSalaryAmount: Double | 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 - })), - }) - .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 - positionSalaryAmount: Double | null - mouthSalaryAmount: Double | 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 - })), - }) - .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 - commandYear: number - templateDoc: string | null - amount: Double | null - positionSalaryAmount: Double | null - mouthSalaryAmount: Double | 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" - 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 = "PENDING" - 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 = "REPORT" - await this.appointRepository.save(list) - }) - ) - return new HttpSuccess() - } + 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); + + /** + * 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, + }; + + const achievements = await this.evaluateAchievementRepository.find({ + select: ["evaluate_expect_level", "evaluate_output_level"], + where: { evaluate_id: evaluate.id }, + }); + + if (!achievements) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + let achievement: any = []; + await Promise.all( + achievements.map(async (element) => { + const evaluate_expect_level = await { + 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 ? "/" : "", + }; + + const evaluate_output_level = await { + 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 ? "/" : "", + }; + + achievement.push({ + ...element, + evaluate_expect_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 experimentee = await { + ...experimenteeData, + name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, + PositionLevelName: experimenteeData.positionLevelName, + PositionLineName: experimenteeData.positionLineName, + Position: experimenteeData.positionName, + Department: "-", + OrganizationOrganization: experimenteeData.orgRootName, + Oc: experimenteeData.organization, + }; + + 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 experimentee = await { + ...experimenteeData, + name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, + PositionLevelName: experimenteeData.positionLevelName, + PositionLineName: experimenteeData.positionLineName, + Position: experimenteeData.positionName, + Department: "-", + OrganizationOrganization: experimenteeData.orgRootName, + Oc: experimenteeData.organization, + }; + + 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, + }; + + 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 experimentee = await { + ...experimenteeData, + name: `${experimenteeData.prefixName}${experimenteeData.firstName} ${experimenteeData.lastName}`, + PositionLevelName: experimenteeData.positionLevelName, + PositionLineName: experimenteeData.positionLineName, + Position: experimenteeData.positionName, + Department: "-", + OrganizationOrganization: experimenteeData.orgRootName, + Oc: experimenteeData.organization, + }; + + 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, + }; + }), + ); + + 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; + positionSalaryAmount: Double | null; + mouthSalaryAmount: Double | 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, + })), + }) + .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; + positionSalaryAmount: Double | null; + mouthSalaryAmount: Double | 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, + })), + }) + .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; + commandYear: number; + templateDoc: string | null; + amount: Double | null; + positionSalaryAmount: Double | null; + mouthSalaryAmount: Double | 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"; + 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 = "PENDING"; + 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 = "REPORT"; + 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); + } } diff --git a/src/entities/AppointDirector.ts b/src/entities/AppointDirector.ts index 3ce7086..226b965 100644 --- a/src/entities/AppointDirector.ts +++ b/src/entities/AppointDirector.ts @@ -45,10 +45,10 @@ export class AppointDirector extends EntityBase { @Column({ type: "enum", - enum: ["chairman", "committee"], + enum: ["chairman", "committee", "caregiver"], nullable: false, default: "committee", - comment: "บทบาท ประธาน/กรรมการ", + comment: "บทบาท ประธาน/กรรมการ/ผู้ดูแล", }) role: string; diff --git a/src/entities/Personal.ts b/src/entities/Personal.ts index 5fe85b8..b360f43 100644 --- a/src/entities/Personal.ts +++ b/src/entities/Personal.ts @@ -1,11 +1,4 @@ -import { - Entity, - Column, - PrimaryGeneratedColumn, - OneToOne, - JoinColumn, - OneToMany, -} from "typeorm"; +import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { Assign } from "./Assign"; @@ -55,8 +48,7 @@ export class Personal extends EntityBase { @Column({ type: Boolean, - comment: - "สถานะการทดลองงาน 1 คืออยู่ระหว่างการทดลองงาน, 0 คือไม่อยู่ระหว่างการทดลองงาน", + comment: "สถานะการทดลองงาน 1 คืออยู่ระหว่างการทดลองงาน, 0 คือไม่อยู่ระหว่างการทดลองงาน", default: 0, }) isProbation: number; @@ -109,6 +101,21 @@ export class Personal extends EntityBase { }) idcard: string; + @Column({ nullable: true, comment: "id หน่วยงาน root", default: null }) + root: string; + + @Column({ nullable: true, comment: "id หน่วยงาน child1", default: null }) + child1: string; + + @Column({ nullable: true, comment: "id หน่วยงาน child2", default: null }) + child2: string; + + @Column({ nullable: true, comment: "id หน่วยงาน child3", default: null }) + child3: string; + + @Column({ nullable: true, comment: "id หน่วยงาน child4", default: null }) + child4: string; + @OneToMany(() => Assign, (assign: Assign) => assign.personal_id) @JoinColumn({ name: "personal_id" }) assign: Assign[]; diff --git a/src/migration/1729823259868-alterColumnAppoint.ts b/src/migration/1729823259868-alterColumnAppoint.ts new file mode 100644 index 0000000..6df3446 --- /dev/null +++ b/src/migration/1729823259868-alterColumnAppoint.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AlterColumnAppoint1729823259868 implements MigrationInterface { + name = 'AlterColumnAppoint1729823259868' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`appointDirector\` CHANGE \`role\` \`role\` enum ('chairman', 'committee', 'caregiver') NOT NULL COMMENT 'บทบาท ประธาน/กรรมการ/ผู้ดูแล' DEFAULT 'committee'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`appointDirector\` CHANGE \`role\` \`role\` enum ('chairman', 'committee') NOT NULL COMMENT 'บทบาท ประธาน/กรรมการ' DEFAULT 'committee'`); + } + +} diff --git a/src/migration/1729832583096-addColumnPersonal.ts b/src/migration/1729832583096-addColumnPersonal.ts new file mode 100644 index 0000000..0b1bfa8 --- /dev/null +++ b/src/migration/1729832583096-addColumnPersonal.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddColumnPersonal1729832583096 implements MigrationInterface { + name = 'AddColumnPersonal1729832583096' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`root\` varchar(255) NULL COMMENT 'id หน่วยงาน root'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child1\` varchar(255) NULL COMMENT 'id หน่วยงาน child1'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child2\` varchar(255) NULL COMMENT 'id หน่วยงาน child2'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child3\` varchar(255) NULL COMMENT 'id หน่วยงาน child3'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child4\` varchar(255) NULL COMMENT 'id หน่วยงาน child4'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child4\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child3\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child2\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child1\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`root\``); + } + +}