add salary position

This commit is contained in:
kittapath 2025-02-24 11:04:17 +07:00
parent 54554d140e
commit 0f9af5699a
3 changed files with 461 additions and 25 deletions

View file

@ -47,7 +47,7 @@ import { OFFICER } from "../entities/OFFICER";
import { Position } from "../entities/Position";
import { PosMaster } from "../entities/PosMaster";
import { positionOfficer } from "../entities/positionOfficer";
import { uuidv7 } from "uuidv7";
@Route("api/v1/org/upload")
@Tags("UPLOAD")
@Security("bearerAuth")
@ -323,16 +323,28 @@ export class ImportDataController extends Controller {
async UploadFileSQLSalary(@Request() request: { user: Record<string, any> }) {
let rowCount = 0;
let null_: any = null;
let sqlStatements: string[] = [];
const [profiles, total] = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile")
.select(["profile.citizenId", "profile.id"])
.orderBy("profile.citizenId", "ASC")
.where("profile.citizenId = '3101702379675'")
// .skip(0)
// .take(10000)
// .where("profile.citizenId = '3101702379675'")
.skip(0)
.take(10000)
.getManyAndCount();
var _profiles: ProfileSalary[] = [];
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`;
fs.appendFile(filePath, csvData, (err) => {
if (err) {
console.error("Error writing CSV file:", err);
} else {
console.log("Salary profiles successfully written to salaryProfile.csv");
}
});
await Promise.all(
profiles.map(async (_item) => {
const existingProfile = await this.positionOfficerRepo.find({
@ -342,23 +354,146 @@ export class ImportDataController extends Controller {
order_move_position: "ASC",
},
});
let order = 1;
await Promise.all(
existingProfile.map(async (item) => {
rowCount++;
const profileSalary: any = new ProfileSalary();
profileSalary.profileId = _item.id;
profileSalary.order = item.order_move_position; ///
profileSalary.order = order;
order = order + 1;
profileSalary.commandNo = item.mp_command_num;
profileSalary.commandYear = item.cur_year;
profileSalary.commandYear = item.cur_year > 2500 ? item.cur_year - 543 : item.cur_year;
profileSalary.commandDateSign = item.mp_command_date;
profileSalary.commandDateAffect = item.mp_pos_date;
profileSalary.commandCode = item.flag_to_name_code;
profileSalary.commandName = item.flag_to_name;
if (
[
"0",
"11",
"22",
"31",
"39",
"45",
"46",
"47",
"49",
"50",
"51",
"56",
"60",
"61",
"62",
"99",
].includes(item.flag_to_name_code)
) {
profileSalary.commandCode = "0";
profileSalary.commandName = "อื่น ๆ";
} else if (["1", "58"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "1";
profileSalary.commandName = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้";
} else if (["23"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "2";
profileSalary.commandName = "บรรจุและแต่งตั้งผู้ได้รับคัดเลือก";
} else if (["3", "6", "34", "36", "37"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "3";
profileSalary.commandName = "แต่งตั้ง ย้าย";
} else if (["10", "55"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "4";
profileSalary.commandName = "เลื่อน";
} else if (["14"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "5";
profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ";
} else if (
["8", "20", "24", "25", "43", "44", "52", "66", "67"].includes(item.flag_to_name_code)
) {
profileSalary.commandCode = "6";
profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
} else if (["-"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "7";
profileSalary.commandName = "เงินพิเศษอื่น ๆ";
} else if (["38", "40", "53", "54"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "8";
profileSalary.commandName = "ปรับโครงสร้าง";
} else if (["12"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "9";
profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ";
} else if (["2", "18"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "10";
profileSalary.commandName = "บรรจุกลับ";
} else if (["4", "32", "33"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "11";
profileSalary.commandName = "รับโอน";
} else if (["5"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "12";
profileSalary.commandName = "ให้โอน";
} else if (["15", "95"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "13";
profileSalary.commandName = "แก้ไขคำสั่ง";
} else if (["19"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "14";
profileSalary.commandName = "ยกเลิกคำสั่ง";
} else if (["27", "35"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "15";
profileSalary.commandName = "ลาออกจากราชการ";
} else if (
["13", "17", "21", "28", "29", "30", "59"].includes(item.flag_to_name_code)
) {
profileSalary.commandCode = "16";
profileSalary.commandName = "พ้นจากราชการ";
} else if (["7", "9", "16", "26", "63", "68"].includes(item.flag_to_name_code)) {
profileSalary.commandCode = "17";
profileSalary.commandName = "รักษาราชการ, ช่วยราชการ";
}
if (
item.flag_to_name == "" &&
(item.flag_to_name_code == "เลื่อน 1 ขั้นและเลื่อนระดับ" ||
item.flag_to_name_code == "เลื่อน 0.5 ขั้นและเลื่อนระดับ" ||
item.flag_to_name_code == "ลาศึกษาต่อ")
) {
profileSalary.commandCode = "0";
profileSalary.commandName = "อื่น ๆ";
} else if (item.flag_to_name == "" && item.flag_to_name_code == "เลื่อนเงินเดือน") {
profileSalary.commandCode = "5";
profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ";
} else if (
item.flag_to_name == "" &&
(item.flag_to_name_code == "ปรับตามบัญชีเงินเดือนใหม่" ||
item.flag_to_name_code == "เลื่อนเงินเดือน" ||
item.flag_to_name_code == "ปรับเงินเดือนตาม กพ.")
) {
profileSalary.commandCode = "6";
profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
} else if (
item.flag_to_name == "" &&
item.flag_to_name_code == "แต่งตั้งตามการปรับปรุงโครงฯ"
) {
profileSalary.commandCode = "8";
profileSalary.commandName = "ปรับโครงสร้าง";
} else if (
item.flag_to_name == "" &&
item.flag_to_name_code == "พ้นทดลองปฏิบัติราชการ"
) {
profileSalary.commandCode = "9";
profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ";
} else if (item.flag_to_name == "" && item.flag_to_name_code == "ให้โอนมา") {
profileSalary.commandCode = "11";
profileSalary.commandName = "รับโอน";
} else if (
item.flag_to_name == "" &&
item.flag_to_name_code == "โอนไปปฏิบัติราชการที่อื่น"
) {
profileSalary.commandCode = "12";
profileSalary.commandName = "ให้โอน";
} else if (item.flag_to_name == "" && item.flag_to_name_code == "ยกเลิกคำสั่ง") {
profileSalary.commandCode = "14";
profileSalary.commandName = "ยกเลิกคำสั่ง";
} else if (item.flag_to_name == "" && item.flag_to_name_code == "รักษาการในตำแหน่ง") {
profileSalary.commandCode = "17";
profileSalary.commandName = "รักษาราชการ, ช่วยราชการ";
}
profileSalary.posNoAbb = item.pos_num_name;
profileSalary.posNo = item.pos_num_code;
profileSalary.positionName = item.work_line_name;
profileSalary.positionCee = item.mp_cee;
var positionType = "";
var positionLevel = "";
if (item.mp_cee == "21") {
@ -406,20 +541,11 @@ export class ImportDataController extends Controller {
} else if (item.mp_cee == "35") {
positionType = "บริหาร";
positionLevel = "สูง";
} else {
profileSalary.positionCee = item.mp_cee;
}
var _type = await this.posTypeRepo.findOne({
where: { posTypeName: positionType },
});
profileSalary.positionType = _type == null ? null_ : _type.id;
if (_type != null) {
var _level = await this.posLevelRepo.findOne({
where: {
posLevelName: positionLevel,
posTypeId: _type.id,
},
});
profileSalary.positionLevel = _level == null ? null_ : _level.id;
}
profileSalary.positionType = positionType;
profileSalary.positionLevel = positionLevel;
profileSalary.orgRoot = item.department_name;
profileSalary.orgChild1 = item.division_name;
profileSalary.orgChild2 = item.section_name;
@ -452,14 +578,66 @@ export class ImportDataController extends Controller {
profileSalary.lastUpdateFullName = request.user.name;
profileSalary.createdAt = new Date();
profileSalary.lastUpdatedAt = new Date();
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
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?.toISOString()?.split("T")[0] || "NULL"}","${profileSalary.createdUserId || "NULL"}","${profileSalary.lastUpdatedAt?.toISOString()?.split("T")[0] || "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?.toISOString()?.split("T")[0] || "NULL"}","${profileSalary.commandDateAffect?.toISOString()?.split("T")[0] || "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?.toISOString()?.split("T")[0] || "NULL"}","${profileSalary.isGovernment || "NULL"}","${profileSalary.commandId || "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,
);
}
});
// await this.salaryRepo.save(profileSalary);
}),
);
order = 1;
}),
);
console.log(rowCount);
// // 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();
}