update commander-director-position
This commit is contained in:
parent
e327e28bf6
commit
2d1fc8b05f
3 changed files with 337 additions and 31 deletions
|
|
@ -47,7 +47,8 @@ import { OFFICER } from "../entities/OFFICER";
|
|||
import { Position } from "../entities/Position";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { positionOfficer } from "../entities/positionOfficer";
|
||||
// import { uuidv7 } from "uuidv7";
|
||||
import { uuidv7 } from "uuidv7";
|
||||
import { ProfileSalaries } from "../entities/ProfileSalaries";
|
||||
@Route("api/v1/org/upload")
|
||||
@Tags("UPLOAD")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -62,6 +63,7 @@ export class ImportDataController extends Controller {
|
|||
private posLevelRepo = AppDataSource.getRepository(PosLevel);
|
||||
private posTypeRepo = AppDataSource.getRepository(PosType);
|
||||
private positionOfficerRepo = AppDataSource.getRepository(positionOfficer);
|
||||
private ProfileSalariesRepo = AppDataSource.getRepository(ProfileSalaries);
|
||||
private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_OFFICER_FAMILY);
|
||||
private HR_EDUCATIONRepo = AppDataSource.getRepository(HR_EDUCATION);
|
||||
private HR_PERSONAL_OFFICER_ADDRESSRepo = AppDataSource.getRepository(
|
||||
|
|
@ -330,13 +332,29 @@ export class ImportDataController extends Controller {
|
|||
.select(["profile.citizenId", "profile.id"])
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
// .where("profile.citizenId = '3101702379675'")
|
||||
.skip(0)
|
||||
.take(10000)
|
||||
.where({
|
||||
citizenId: In([
|
||||
// "1100600109451",
|
||||
// "1209900075508",
|
||||
// "1739900231556",
|
||||
// "1809900305214",
|
||||
// "1920600228762",
|
||||
// "3101600963742",
|
||||
// "3102401171243",
|
||||
// "3120100454406",
|
||||
// "3180100306172",
|
||||
// "3700100094722",
|
||||
// "3809900116957",
|
||||
"3940900213929",
|
||||
]),
|
||||
})
|
||||
// .skip(10000)
|
||||
// .take(20000)
|
||||
.getManyAndCount();
|
||||
var _profiles: ProfileSalary[] = [];
|
||||
const filePath = path.join(__dirname, "salaryProfile.csv");
|
||||
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"\n`;
|
||||
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) {
|
||||
|
|
@ -364,8 +382,20 @@ export class ImportDataController extends Controller {
|
|||
order = order + 1;
|
||||
profileSalary.commandNo = item.mp_command_num;
|
||||
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.commandDateSign =
|
||||
item.mp_command_date == null
|
||||
? null_
|
||||
: new Date(item.mp_command_date.setDate(item.mp_command_date.getDate() + 1))
|
||||
.toISOString()
|
||||
.replace("T", " ")
|
||||
.substring(0, 19);
|
||||
profileSalary.commandDateAffect =
|
||||
item.mp_pos_date == null
|
||||
? null_
|
||||
: new Date(item.mp_pos_date.setDate(item.mp_pos_date.getDate() + 1))
|
||||
.toISOString()
|
||||
.replace("T", " ")
|
||||
.substring(0, 19);
|
||||
if (
|
||||
[
|
||||
"0",
|
||||
|
|
@ -445,52 +475,203 @@ export class ImportDataController extends Controller {
|
|||
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 == "ลาศึกษาต่อ")
|
||||
item.flag_to_name_code == null &&
|
||||
(item.flag_to_name == "เลื่อน 1 ขั้นและเลื่อนระดับ" ||
|
||||
item.flag_to_name == "เลื่อน 0.5 ขั้นและเลื่อนระดับ" ||
|
||||
item.flag_to_name == "ลาศึกษาต่อ")
|
||||
) {
|
||||
profileSalary.commandCode = "0";
|
||||
profileSalary.commandName = "อื่น ๆ";
|
||||
} else if (item.flag_to_name == "" && item.flag_to_name_code == "เลื่อนเงินเดือน") {
|
||||
} else if (item.flag_to_name_code == null && item.flag_to_name == "เลื่อนเงินเดือน") {
|
||||
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 == "ปรับเงินเดือนตาม กพ.")
|
||||
item.flag_to_name_code == null &&
|
||||
(item.flag_to_name == "ปรับตามบัญชีเงินเดือนใหม่" ||
|
||||
item.flag_to_name == "เลื่อนเงินเดือน" ||
|
||||
item.flag_to_name == "ปรับเงินเดือนตาม กพ.")
|
||||
) {
|
||||
profileSalary.commandCode = "6";
|
||||
profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
|
||||
} else if (
|
||||
item.flag_to_name == "" &&
|
||||
item.flag_to_name_code == "แต่งตั้งตามการปรับปรุงโครงฯ"
|
||||
item.flag_to_name_code == null &&
|
||||
item.flag_to_name == "แต่งตั้งตามการปรับปรุงโครงฯ"
|
||||
) {
|
||||
profileSalary.commandCode = "8";
|
||||
profileSalary.commandName = "ปรับโครงสร้าง";
|
||||
} else if (
|
||||
item.flag_to_name == "" &&
|
||||
item.flag_to_name_code == "พ้นทดลองปฏิบัติราชการ"
|
||||
item.flag_to_name_code == null &&
|
||||
item.flag_to_name == "พ้นทดลองปฏิบัติราชการ"
|
||||
) {
|
||||
profileSalary.commandCode = "9";
|
||||
profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ";
|
||||
} else if (item.flag_to_name == "" && item.flag_to_name_code == "ให้โอนมา") {
|
||||
} else if (item.flag_to_name_code == null && item.flag_to_name == "ให้โอนมา") {
|
||||
profileSalary.commandCode = "11";
|
||||
profileSalary.commandName = "รับโอน";
|
||||
} else if (
|
||||
item.flag_to_name == "" &&
|
||||
item.flag_to_name_code == "โอนไปปฏิบัติราชการที่อื่น"
|
||||
item.flag_to_name_code == null &&
|
||||
item.flag_to_name == "โอนไปปฏิบัติราชการที่อื่น"
|
||||
) {
|
||||
profileSalary.commandCode = "12";
|
||||
profileSalary.commandName = "ให้โอน";
|
||||
} else if (item.flag_to_name == "" && item.flag_to_name_code == "ยกเลิกคำสั่ง") {
|
||||
} else if (item.flag_to_name_code == null && item.flag_to_name == "ยกเลิกคำสั่ง") {
|
||||
profileSalary.commandCode = "14";
|
||||
profileSalary.commandName = "ยกเลิกคำสั่ง";
|
||||
} else if (item.flag_to_name == "" && item.flag_to_name_code == "รักษาการในตำแหน่ง") {
|
||||
} else if (item.flag_to_name_code == null && item.flag_to_name == "รักษาการในตำแหน่ง") {
|
||||
profileSalary.commandCode = "17";
|
||||
profileSalary.commandName = "รักษาราชการ, ช่วยราชการ";
|
||||
}
|
||||
if (
|
||||
(profileSalary.commandCode == null || profileSalary.commandCode == undefined) &&
|
||||
(profileSalary.commandName == null || profileSalary.commandName == undefined)
|
||||
) {
|
||||
if (
|
||||
[
|
||||
"อื่นๆ",
|
||||
"กลับไปปฏิบัติงานทางต้นสังกัด",
|
||||
"เปลี่ยนประเภทข้าราชการ",
|
||||
"โอนสับเปลี่ยน",
|
||||
"เข้ารับฝึกอบรม",
|
||||
"ดูงาน",
|
||||
"ศึกษาต่อ",
|
||||
"ขยายเวลาเข้ารับการฝึกอบรม",
|
||||
"ขยายเวลาศึกษาต่อ",
|
||||
"รายงานตัวกลับเข้าปฏิบัติราชการ",
|
||||
"ไม่ได้เลื่อนขั้น",
|
||||
"เลือนเงินเดือนและระดับ",
|
||||
"เลื่อนเงินเดือนและระดับ",
|
||||
"ตัดเงินเดือน",
|
||||
"ลดขั้นเงินเดือน",
|
||||
"ให้ข้าราชการกลับเข้ารับราชการ",
|
||||
"ไม่ระบุ",
|
||||
].includes(item.flag_to_name)
|
||||
) {
|
||||
profileSalary.commandCode = "0";
|
||||
profileSalary.commandName = "อื่น ๆ";
|
||||
} else if (
|
||||
[
|
||||
"บรรจุและแต่งตั้งผู้สอบแข่งขันได้",
|
||||
"ทดลองปฎิบัติราชการ",
|
||||
"ทดลองปฏิบัติราชการและปรับวุฒิ",
|
||||
"บรรจุใหม่",
|
||||
].includes(item.flag_to_name)
|
||||
) {
|
||||
profileSalary.commandCode = "1";
|
||||
profileSalary.commandName = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้";
|
||||
} else if (["บรรจุและแต่งตั้งผู้ได้รับการคัดเลือก"].includes(item.flag_to_name)) {
|
||||
profileSalary.commandCode = "2";
|
||||
profileSalary.commandName = "บรรจุและแต่งตั้งผู้ได้รับคัดเลือก";
|
||||
} else if (
|
||||
[
|
||||
"แต่งตั้ง (ย้ายสับเปลี่ยน)",
|
||||
"แต่งตั้ง (ย้าย)",
|
||||
"แต่งตั้ง",
|
||||
"เปลี่ยนสายงาน",
|
||||
"เปลี่ยนตำแหน่ง",
|
||||
"ตัดโอนตำแหน่ง",
|
||||
].includes(item.flag_to_name)
|
||||
) {
|
||||
profileSalary.commandCode = "3";
|
||||
profileSalary.commandName = "แต่งตั้ง ย้าย";
|
||||
} else if (["เลื่อนและแต่งตั้ง", "เลื่อนระดับ"].includes(item.flag_to_name)) {
|
||||
profileSalary.commandCode = "4";
|
||||
profileSalary.commandName = "เลื่อน";
|
||||
} else if (["เลื่อนขั้นเงินเดือน", "เลื่อนเงินเดือน"].includes(item.flag_to_name)) {
|
||||
profileSalary.commandCode = "5";
|
||||
profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ";
|
||||
} else if (
|
||||
[
|
||||
"ปรับเงินเดือนตามคุณวุฒิ",
|
||||
"ได้รับเงินตอบแทนพิเศษ",
|
||||
"เงินเพิ่มการครองชีพชั่วคราว",
|
||||
"เลื่อนขั้นเงินเดือนกรณีพิเศษ",
|
||||
"ปรับอัตราเงินเดือนตามบัญชีอัตราเงินเดือนใหม่ ท้าย พ.ร.บ. เงินเดือนและเงินประจำตำ",
|
||||
"ปรับอัตราเงินเดือนตามพระราชกฤษฎีกา การปรับอัตราเงินเดือนของข้าราชการ",
|
||||
"เลื่อนขั้นเงินเดือน (เพิ่มเติม)",
|
||||
"ปรับอัตราเงินเดือน",
|
||||
"ให้ข้าราชการได้รับเงินเดือนตามคุณวุฒิ",
|
||||
].includes(item.flag_to_name)
|
||||
) {
|
||||
profileSalary.commandCode = "6";
|
||||
profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ";
|
||||
} else if (["--"].includes(item.flag_to_name)) {
|
||||
profileSalary.commandCode = "7";
|
||||
profileSalary.commandName = "เงินพิเศษอื่น ๆ";
|
||||
} else if (
|
||||
["ปรับโครงสร้าง", "แต่งตั้ง (จัดคนลงกรอบ)", "แต่งตั้งตามแผนอัตรากำลังฯ"].includes(
|
||||
item.flag_to_name,
|
||||
)
|
||||
) {
|
||||
profileSalary.commandCode = "8";
|
||||
profileSalary.commandName = "ปรับโครงสร้าง";
|
||||
} else if (["พ้นทดลองปฏิบัติราชการ"].includes(item.flag_to_name)) {
|
||||
profileSalary.commandCode = "9";
|
||||
profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ";
|
||||
} else if (
|
||||
[
|
||||
"บรรจุกลับ",
|
||||
"บรรจุกลับข้าราชการ",
|
||||
"บรรจุและแต่งตั้งผู้ไปรับราชการทหารกลับเข้ารับราชการ",
|
||||
].includes(item.flag_to_name)
|
||||
) {
|
||||
profileSalary.commandCode = "10";
|
||||
profileSalary.commandName = "บรรจุกลับ";
|
||||
} else if (
|
||||
[
|
||||
"รับโอนข้าราชการตามกฎหมายอื่น",
|
||||
"รับโอนข้าราชการตามกฎหมายอื่น ผู้สอบแข่งขันได้",
|
||||
"รับโอนข้าราชการตามกฏหมายอื่น โดยการคัดเลือก",
|
||||
].includes(item.flag_to_name)
|
||||
) {
|
||||
profileSalary.commandCode = "11";
|
||||
profileSalary.commandName = "รับโอน";
|
||||
} else if (["ให้โอน"].includes(item.flag_to_name)) {
|
||||
profileSalary.commandCode = "12";
|
||||
profileSalary.commandName = "ให้โอน";
|
||||
} else if (["แก้ไขคำสั่ง"].includes(item.flag_to_name)) {
|
||||
profileSalary.commandCode = "13";
|
||||
profileSalary.commandName = "แก้ไขคำสั่ง";
|
||||
} else if (["ยกเลิกคำสั่ง"].includes(item.flag_to_name)) {
|
||||
profileSalary.commandCode = "14";
|
||||
profileSalary.commandName = "ยกเลิกคำสั่ง";
|
||||
} else if (
|
||||
[
|
||||
"ลาออกจากราชการ",
|
||||
"พ้นจากราชการ/ลาออกจากราชการตามมาตรการพัฒนาและบริหารกำลังคน",
|
||||
].includes(item.flag_to_name)
|
||||
) {
|
||||
profileSalary.commandCode = "15";
|
||||
profileSalary.commandName = "ลาออกจากราชการ";
|
||||
} else if (
|
||||
[
|
||||
"พ้นจากราชการ/เพื่อไปปฏิบัติราชการทหาร",
|
||||
"เกษียณ",
|
||||
"ไม่พ้นทดลองปฏิบัติราชการ",
|
||||
"พ้นจากราชการ/ให้ออก",
|
||||
"พ้นจากราชการ/ไล่ออก",
|
||||
"พ้นจากราชการ/เสียชีวิต",
|
||||
"พ้นจากราชการ/ปลดออก",
|
||||
].includes(item.flag_to_name)
|
||||
) {
|
||||
profileSalary.commandCode = "16";
|
||||
profileSalary.commandName = "พ้นจากราชการ";
|
||||
} else if (
|
||||
[
|
||||
"แต่งตั้งข้าราชการรักษาราชการแทน",
|
||||
"ช่วยราชการ",
|
||||
"รักษาการ",
|
||||
"รักษาราชการแทน",
|
||||
"มอบหมายให้ปฏิบัติหน้าที่",
|
||||
"มอบหมายข้าราชการปฏิบัติหน้าที่แทน",
|
||||
].includes(item.flag_to_name)
|
||||
) {
|
||||
profileSalary.commandCode = "17";
|
||||
profileSalary.commandName = "รักษาราชการ, ช่วยราชการ";
|
||||
} else {
|
||||
profileSalary.commandCode = "0";
|
||||
profileSalary.commandName = item.flag_to_name;
|
||||
}
|
||||
}
|
||||
profileSalary.posNoAbb = item.pos_num_name;
|
||||
profileSalary.posNo = item.pos_num_code;
|
||||
profileSalary.positionName = item.work_line_name;
|
||||
|
|
@ -558,6 +739,8 @@ export class ImportDataController extends Controller {
|
|||
profileSalary.positionExecutive = item.admin_name;
|
||||
profileSalary.amount = item.salary;
|
||||
profileSalary.remark = item.remark;
|
||||
profileSalary.refId = item.id;
|
||||
profileSalary.isEntry = false;
|
||||
|
||||
const sal_pos_amount_1: any =
|
||||
item.sal_pos_amount_1 == null || item.sal_pos_amount_1 == ""
|
||||
|
|
@ -576,10 +759,10 @@ export class ImportDataController extends Controller {
|
|||
profileSalary.createdFullName = request.user.name;
|
||||
profileSalary.lastUpdateUserId = request.user.sub;
|
||||
profileSalary.lastUpdateFullName = request.user.name;
|
||||
profileSalary.createdAt = new Date();
|
||||
profileSalary.lastUpdatedAt = new Date();
|
||||
// const result = uuidv7();
|
||||
// profileSalary.id = result;
|
||||
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
|
||||
|
|
@ -599,7 +782,8 @@ export class ImportDataController extends Controller {
|
|||
|
||||
// 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`;
|
||||
console.log(profileSalary.commandDateSign);
|
||||
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
|
||||
|
|
@ -1693,6 +1877,7 @@ export class ImportDataController extends Controller {
|
|||
},
|
||||
});
|
||||
|
||||
//order xxxxxxxxxxxxxxxx
|
||||
await Promise.all(
|
||||
IMPORT_CHILD.map(async (item) => {
|
||||
const orgRoot = new OrgRoot();
|
||||
|
|
@ -2092,4 +2277,110 @@ export class ImportDataController extends Controller {
|
|||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary เงินเดือน ข้าราชการ
|
||||
*/
|
||||
@Post("uploadProfileSalary-OfficerEntry")
|
||||
async UploadFileSQLSalaryEntry(@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(10000)
|
||||
.take(20000)
|
||||
.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"\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.ProfileSalariesRepo.find({
|
||||
where: { ProfileId: _item.citizenId },
|
||||
order: {
|
||||
Order: "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;
|
||||
|
||||
profileSalary.commandDateAffect =
|
||||
item.Date == null
|
||||
? null_
|
||||
: new Date(item.Date.setDate(item.Date.getDate() + 1))
|
||||
.toISOString()
|
||||
.replace("T", " ")
|
||||
.substring(0, 19);
|
||||
profileSalary.remark = item.SalaryRef + item.PositionName;
|
||||
profileSalary.amount = item.Amount;
|
||||
profileSalary.positionSalaryAmount = item.PositionSalaryAmount;
|
||||
const str = item.PosNoName;
|
||||
const parts = str.split(" ");
|
||||
if (parts.length > 1) {
|
||||
const posNo = parts.at(-1);
|
||||
const posNoAbb = parts.slice(0, -1).join(" ");
|
||||
profileSalary.posNoAbb = posNoAbb;
|
||||
profileSalary.posNo = posNo;
|
||||
}
|
||||
profileSalary.posLevel = this.canConvertToInt(item.PositionLevelName)
|
||||
? null_
|
||||
: item.PositionLevelName;
|
||||
profileSalary.posCee = this.canConvertToInt(item.PositionLevelName)
|
||||
? item.PositionLevelName
|
||||
: null_;
|
||||
//xxxxxxxxxxxxxxxxx
|
||||
profileSalary.posType = item.PositionTypeName;
|
||||
profileSalary.isEntry = true;
|
||||
|
||||
profileSalary.createdUserId = request.user.sub;
|
||||
profileSalary.createdFullName = request.user.name;
|
||||
profileSalary.lastUpdateUserId = request.user.sub;
|
||||
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(profileSalary.commandDateSign);
|
||||
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"}"\n`;
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
});
|
||||
}),
|
||||
);
|
||||
order = 1;
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
canConvertToInt(str: string) {
|
||||
const num = Number(str);
|
||||
return Number.isInteger(num);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1739,7 +1739,8 @@ export class ProfileController extends Controller {
|
|||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||
},
|
||||
});
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการครองตำแหน่ง");
|
||||
// return new HttpSuccess({ data: [], total: 0 });
|
||||
} else if ((posMaster?.current_holder?.posLevel?.posLevelAuthority ?? null) == "GOVERNOR") {
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,6 +203,13 @@ export class ProfileSalary extends EntityBase {
|
|||
})
|
||||
remark: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "refId",
|
||||
default: null,
|
||||
})
|
||||
refId: number;
|
||||
|
||||
@Column({
|
||||
comment: "วันที่",
|
||||
type: "datetime",
|
||||
|
|
@ -217,6 +224,13 @@ export class ProfileSalary extends EntityBase {
|
|||
})
|
||||
isGovernment: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ข้อมูลจาก Entry",
|
||||
default: null,
|
||||
})
|
||||
isEntry: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue