noti employee

This commit is contained in:
mamoss 2025-04-29 17:54:32 +07:00
parent 5e4f119730
commit c72e1bf3c9
2 changed files with 341 additions and 365 deletions

View file

@ -435,31 +435,38 @@ export class ImportDataController extends Controller {
// ]),
// })
.leftJoinAndSelect("profile.profileSalary", "profileSalary")
// .where({citizenId: "1720700018869"})
// .where({ citizenId: "3101702379675" })
.where("profileSalary.id IS NULL")
// .skip(0)
// .take(10000)
.getManyAndCount();
var _profiles: ProfileSalary[] = [];
const filePath = path.join(__dirname, "salaryProfile1.csv");
// CSV Header
let csvData = `"id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId","refId"\n`;
fs.appendFile(filePath, csvData, (err) => {
if (err) {
console.error("Error writing CSV file:", err);
} else {
console.log("Salary profiles successfully written to salaryProfile.csv");
}
});
for await (const _item of profiles) {
// ดึงข้อมูลมาโดยไม่ใส่ order
const existingProfile = await this.HR_POSITION_OFFICERRepo.find({
where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "1" },
order: {
MP_POS_DATE: "ASC",
ORDER_MOVE_POSITION: "ASC",
},
});
// sort ด้วย JavaScript
existingProfile.sort((a, b) => {
let dateA = new Date().getTime();
let dateB = new Date().getTime();
if (a.MP_POS_DATE) {
const [datePart] = a.MP_POS_DATE.split(" ");
const [day, month, year] = datePart.split("/");
dateA = new Date(`${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`).getTime();
}
if (b.MP_POS_DATE) {
const [datePart] = b.MP_POS_DATE.split(" ");
const [day, month, year] = datePart.split("/");
dateB = new Date(`${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`).getTime();
}
if (dateA !== dateB) {
return dateA - dateB; // ASC
}
return a.ORDER_MOVE_POSITION - b.ORDER_MOVE_POSITION; // ASC
});
let order = 1;
for await (const item of existingProfile) {
rowCount++;
@ -851,38 +858,8 @@ export class ImportDataController extends Controller {
profileSalary.lastUpdateFullName = request.user.name;
profileSalary.createdAt = new Date().toISOString().split("T")[0];
profileSalary.lastUpdatedAt = new Date().toISOString().split("T")[0];
// const result = uuidv7();
// profileSalary.id = result;
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
// // Generate SQL INSERT Statement using TypeORM QueryBuilder but don't execute it
// const queryBuilder = AppDataSource.createQueryBuilder()
// .insert()
// .into(ProfileSalary)
// .values(profileSalary);
// const sql = queryBuilder.getSql();
// sqlStatements.push(sql);
// _profiles.push(profileSalary);
// save to file
// Define the output file path
// CSV Header
// let csvData = `"id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId"\n`;
// Loop through each salary profile and format data as CSV
// _profiles.forEach((profile) => {
// csvData = `"${profileSalary.id || "NULL"}","${profileSalary.createdAt || "NULL"}","${profileSalary.createdUserId || "NULL"}","${profileSalary.lastUpdatedAt || "NULL"}","${profileSalary.lastUpdateUserId || "NULL"}","${profileSalary.createdFullName || "NULL"}","${profileSalary.lastUpdateFullName || "NULL"}","${profileSalary.profileId || "NULL"}","${profileSalary.profileEmployeeId || "NULL"}","${profileSalary.order || "NULL"}","${profileSalary.commandNo || "NULL"}","${profileSalary.commandYear || "NULL"}","${profileSalary.commandDateSign || "NULL"}","${profileSalary.commandDateAffect || "NULL"}","${profileSalary.commandCode || "NULL"}","${profileSalary.commandName || "NULL"}","${profileSalary.posNoAbb || "NULL"}","${profileSalary.posNo || "NULL"}","${profileSalary.positionName || "NULL"}","${profileSalary.positionType || "NULL"}","${profileSalary.positionLevel || "NULL"}","${profileSalary.positionCee || "NULL"}","${profileSalary.orgRoot || "NULL"}","${profileSalary.orgChild1 || "NULL"}","${profileSalary.orgChild2 || "NULL"}","${profileSalary.orgChild3 || "NULL"}","${profileSalary.orgChild4 || "NULL"}","${profileSalary.positionExecutive || "NULL"}","${profileSalary.amount || 0}","${profileSalary.amountSpecial || 0}","${profileSalary.positionSalaryAmount || 0}","${profileSalary.mouthSalaryAmount || 0}","${profileSalary.remark || "NULL"}","${profileSalary.dateGovernment || "NULL"}","${profileSalary.isGovernment || "NULL"}","${profileSalary.commandId || "NULL"}","${profileSalary.refId || "NULL"}"\n`;
// // });
// // Write the CSV data to the file
// fs.appendFile(filePath, csvData.replace('"NULL"', "NULL"), (err) => {
// if (err) {
// console.error("Error writing CSV file:", err);
// } else {
// console.log("Salary profiles successfully written to salaryProfile.csv: " + rowCount);
// }
// });
try {
await this.salaryRepo.save(profileSalary);
} catch (error) {
@ -891,26 +868,6 @@ export class ImportDataController extends Controller {
}
order = 1;
}
// // console.log(rowCount);
// // Define the output file path
// const filePath = path.join(__dirname, "salaryProfile.csv");
// // CSV Header
// let csvData = `"id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId"\n`;
// // Loop through each salary profile and format data as CSV
// _profiles.forEach((profile) => {
// csvData += `"${profile.id || "NULL"}","${profile.createdAt?.toISOString()?.split("T")[0] || "NULL"}","${profile.createdUserId || "NULL"}","${profile.lastUpdatedAt?.toISOString()?.split("T")[0] || "NULL"}","${profile.lastUpdateUserId || "NULL"}","${profile.createdFullName || "NULL"}","${profile.lastUpdateFullName || "NULL"}","${profile.profileId || "NULL"}","${profile.profileEmployeeId || "NULL"}","${profile.order || "NULL"}","${profile.commandNo || "NULL"}","${profile.commandYear || "NULL"}","${profile.commandDateSign?.toISOString()?.split("T")[0] || "NULL"}","${profile.commandDateAffect?.toISOString()?.split("T")[0] || "NULL"}","${profile.commandCode || "NULL"}","${profile.commandName || "NULL"}","${profile.posNoAbb || "NULL"}","${profile.posNo || "NULL"}","${profile.positionName || "NULL"}","${profile.positionType || "NULL"}","${profile.positionLevel || "NULL"}","${profile.positionCee || "NULL"}","${profile.orgRoot || "NULL"}","${profile.orgChild1 || "NULL"}","${profile.orgChild2 || "NULL"}","${profile.orgChild3 || "NULL"}","${profile.orgChild4 || "NULL"}","${profile.positionExecutive || "NULL"}","${profile.amount || 0}","${profile.amountSpecial || 0}","${profile.positionSalaryAmount || 0}","${profile.mouthSalaryAmount || 0}","${profile.remark || "NULL"}","${profile.dateGovernment?.toISOString()?.split("T")[0] || "NULL"}","${profile.isGovernment || "NULL"}","${profile.commandId || "NULL"}"\n`;
// });
// // Write the CSV data to the file
// fs.writeFile(filePath, csvData, (err) => {
// if (err) {
// console.error("Error writing CSV file:", err);
// } else {
// console.log("Salary profiles successfully written to salaryProfile.csv");
// }
// });
return new HttpSuccess();
}
@ -965,10 +922,27 @@ export class ImportDataController extends Controller {
for await (const _item of profiles) {
const existingProfile = await this.HR_POSITION_EMPLOYEERepo.find({
where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "6" },
order: {
MP_POS_DATE: "ASC",
ORDER_MOVE_POSITION: "ASC",
},
});
// sort ด้วย JavaScript
existingProfile.sort((a, b) => {
let dateA = new Date().getTime();
let dateB = new Date().getTime();
if (a.MP_POS_DATE) {
const [datePart] = a.MP_POS_DATE.split(" ");
const [day, month, year] = datePart.split("/");
dateA = new Date(`${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`).getTime();
}
if (b.MP_POS_DATE) {
const [datePart] = b.MP_POS_DATE.split(" ");
const [day, month, year] = datePart.split("/");
dateB = new Date(`${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`).getTime();
}
if (dateA !== dateB) {
return dateA - dateB; // ASC
}
return a.ORDER_MOVE_POSITION - b.ORDER_MOVE_POSITION; // ASC
});
let order = 1;
for await (const item of existingProfile) {