Merge branch 'main' of ssh://hrms-git.chin.in.th:6611/BMA-HRMS/hrms-api-org

This commit is contained in:
Warunee Tamkoo 2025-07-09 18:00:46 +07:00
commit 8dc4d63bd0
5 changed files with 174 additions and 3 deletions

View file

@ -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();

View file

@ -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();
}
}

View file

@ -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<string, any> }) {
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
*/

View file

@ -108,6 +108,12 @@ export class ProfileTraining extends EntityBase {
})
isDate: boolean;
@Column({
comment: "ข้อมูลจาก Entry",
default: false,
})
isEntry: boolean;
@Column({
nullable: true,
length: 40,

View file

@ -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;
}