From 30c785dc3c2c37fc65d30020cf252320e7958526 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Tue, 8 Jul 2025 23:27:41 +0700 Subject: [PATCH] add entry --- src/app.ts | 7 +- src/controllers/CommandController.ts | 17 +++++ src/controllers/ImportDataController.ts | 56 +++++++++++++++ src/entities/ProfileTraining.ts | 6 ++ src/entities/ProfileTrainings.ts | 91 +++++++++++++++++++++++++ 5 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 src/entities/ProfileTrainings.ts diff --git a/src/app.ts b/src/app.ts index 221a0304..d4d212fc 100644 --- a/src/app.ts +++ b/src/app.ts @@ -40,7 +40,7 @@ async function main() { const APP_HOST = process.env.APP_HOST || "0.0.0.0"; const APP_PORT = +(process.env.APP_PORT || 3000); - const cronTime = "0 8 * * * *"; // ตั้งเวลาทุกวันเวลา 08:00:00 + const cronTime = "0 0 3 * * *"; // ตั้งเวลาทุกวันเวลา 08:00:00 // const cronTime = "*/10 * * * * *"; cron.schedule(cronTime, async () => { try { @@ -51,12 +51,13 @@ async function main() { } }); - const cronTime_command = "0 2 * * * *"; + const cronTime_command = "0 0 2 * * *"; // const cronTime_command = "*/10 * * * * *"; cron.schedule(cronTime_command, async () => { try { const commandController = new CommandController(); await commandController.cronjobCommand(); + await commandController.cronjobTest(); } catch (error) { console.error("Error executing function from controller:", error); } @@ -72,7 +73,7 @@ async function main() { } }); - const cronTime_Tenure = "0 0 * * *"; + const cronTime_Tenure = "0 0 0 * * *"; cron.schedule(cronTime_Tenure, async () => { try { const profileSalaryController = new ProfileSalaryController(); diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 72da68dc..b019e7bd 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -89,6 +89,7 @@ import { OrgRoot } from "../entities/OrgRoot"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; import { ProfileInsignia, CreateProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory"; +import { Gender } from "../entities/Gender"; @Route("api/v1/org/command") @Tags("Command") @Security("bearerAuth") @@ -141,6 +142,7 @@ export class CommandController extends Controller { private orgRootRepository = AppDataSource.getRepository(OrgRoot); private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); + private genderRepo = AppDataSource.getRepository(Gender); /** * API list รายการคำสั่ง @@ -7052,4 +7054,19 @@ export class CommandController extends Controller { }, }); } + + async cronjobTest(@Request() request?: RequestWithUser) { + const gender = { + name: "เพศทางเลือก", + code: "M", + isActive: true, + createdFullName: "system", + createdAt: new Date(), + updatedAt: new Date(), + }; + + await this.genderRepo.save(gender); + + return new HttpSuccess(); + } } diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 2538a59c..d1fb5b20 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -93,6 +93,8 @@ import { ProfileInsignias } from "../entities/ProfileInsignias"; import { ProfileLeave } from "../entities/ProfileLeave"; import { ProfileLeaves } from "../entities/ProfileLeaves"; import { ProfileSalaryTemp } from "../entities/ProfileSalaryTemp"; +import { ProfileTraining } from "../entities/ProfileTraining"; +import { ProfileTrainings } from "../entities/ProfileTrainings"; @Route("api/v1/org/upload") @Tags("UPLOAD") @Security("bearerAuth") @@ -185,6 +187,8 @@ export class ImportDataController extends Controller { private LeaveSummaryRepo = AppDataSource.getRepository(ProfileLeave); private ProfileInsigniasRepo = AppDataSource.getRepository(ProfileInsignias); private InsigniaRepo = AppDataSource.getRepository(ProfileInsignia); + private ProfileTrainingsRepo = AppDataSource.getRepository(ProfileTrainings); + private TrainingRepo = AppDataSource.getRepository(ProfileTraining); private salaryTempRepo = AppDataSource.getRepository(ProfileSalaryTemp); /** @@ -4699,6 +4703,58 @@ export class ImportDataController extends Controller { return new HttpSuccess(); } + /** + * @summary เครื่องราช ข้าราชการ + */ + @Post("uploadProfileTraining-OfficerEntry") + async UploadFileSQLTrainingEntry(@Request() request: { user: Record }) { + let rowCount = 0; + let _null: any = null; + const existingProfile = await this.ProfileTrainingsRepo.find({ + // order: { + // citizenId: "ASC", + // }, + }); + for await (const _item of existingProfile) { + const citizenId: any = _item.createdFullName ?? ""; + const profiles = await this.profileRepo.find({ + where: { citizenId: citizenId }, + // order: { + // Order: "ASC", + // }, + }); + let order = 1; + for await (const item of profiles) { + rowCount++; + const profile: any = new ProfileTraining(); + profile.profileId = item.id; + profile.startDate = _item.startDate; + profile.endDate = _item.endDate; + profile.numberOrder = _item.numberOrder; + profile.topic = _item.topic; + profile.place = _item.place; + profile.dateOrder = _item.dateOrder; + profile.department = _item.department; + profile.duration = _item.duration; + profile.name = _item.name; + profile.yearly = _item.yearly; + profile.isDate = _item.isDate; + + profile.isEntry = true; + profile.createdUserId = request.user.sub; + profile.createdFullName = request.user.name; + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + profile.createdAt = new Date().toISOString().split("T")[0]; + profile.lastUpdatedAt = new Date().toISOString().split("T")[0]; + await this.TrainingRepo.save(profile); + console.log("profiles successfully written to Profile.csv: " + rowCount); + } + order = 1; + } + return new HttpSuccess(); + } + /** * @summary การลา ข้าราชการ */ diff --git a/src/entities/ProfileTraining.ts b/src/entities/ProfileTraining.ts index 30f50c0e..e4b29b70 100644 --- a/src/entities/ProfileTraining.ts +++ b/src/entities/ProfileTraining.ts @@ -108,6 +108,12 @@ export class ProfileTraining extends EntityBase { }) isDate: boolean; + @Column({ + comment: "ข้อมูลจาก Entry", + default: false, + }) + isEntry: boolean; + @Column({ nullable: true, length: 40, diff --git a/src/entities/ProfileTrainings.ts b/src/entities/ProfileTrainings.ts new file mode 100644 index 00000000..3f9211d5 --- /dev/null +++ b/src/entities/ProfileTrainings.ts @@ -0,0 +1,91 @@ +import { Entity, Column } from "typeorm"; +import { EntityBase } from "./base/Base"; + +@Entity("ProfileTrainings") +export class ProfileTrainings extends EntityBase { + @Column({ + nullable: true, + type: "datetime", + comment: "วันเริ่มต้นการฝึกอบรม/ดูงาน ", + default: null, + }) + startDate: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันสิ้นสุดการฝึกอบรม/ดูงาน ", + default: null, + }) + endDate: Date; + + @Column({ + nullable: true, + length: 200, + comment: "เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ ", + default: null, + }) + numberOrder: string; + + @Column({ + nullable: true, + length: 200, + comment: "หัวข้อการฝึกอบรม/ดูงาน ", + default: null, + }) + topic: string; + + @Column({ + nullable: true, + length: 200, + comment: "สถานที่ฝึกอบรม/ดูงาน ", + default: null, + }) + place: string; + + @Column({ + nullable: true, + type: "datetime", + comment: "คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่ ", + default: null, + }) + dateOrder: Date; + + @Column({ + nullable: true, + length: 200, + comment: "หน่วยงานที่รับผิดชอบจัดการฝึกอบรม/ดูงาน ", + default: null, + }) + department: string; + + @Column({ + nullable: true, + length: 200, + comment: "รวมระยะเวลาในการฝึกอบรม/ดูงาน ", + default: null, + }) + duration: string; + + @Column({ + nullable: true, + length: 200, + comment: "ชื่อโครงการ/หลักสูตรการฝึกอบรม ", + default: null, + }) + name: string; + + @Column({ + nullable: true, + comment: "ปีที่อบรม (พ.ศ.) ", + default: null, + }) + yearly: number; + + @Column({ + nullable: true, + comment: "ประเภทช่วงเวลาการศึกษา", + default: null, + }) + isDate: boolean; +}