diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 4ffe05d2..ba243365 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -48,7 +48,7 @@ import { Position } from "../entities/Position"; import { PosMaster } from "../entities/PosMaster"; import { positionOfficer } from "../entities/positionOfficer"; // import { uuidv7 } from "uuidv7"; -import { ProfileSalaries } from "../entities/ProfileSalaries"; +// import { ProfileSalaries } from "../entities/ProfileSalaries"; @Route("api/v1/org/upload") @Tags("UPLOAD") @Security("bearerAuth") @@ -63,7 +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 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( @@ -2278,109 +2278,109 @@ export class ImportDataController extends Controller { return new HttpSuccess(); } - /** - * @summary เงินเดือน ข้าราชการ - */ - @Post("uploadProfileSalary-OfficerEntry") - async UploadFileSQLSalaryEntry(@Request() request: { user: Record }) { - let rowCount = 0; - let null_: any = null; - let sqlStatements: string[] = []; + // /** + // * @summary เงินเดือน ข้าราชการ + // */ + // @Post("uploadProfileSalary-OfficerEntry") + // async UploadFileSQLSalaryEntry(@Request() request: { user: Record }) { + // 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","refId"\n`; + // 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","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"); - } - }); - 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; + // 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.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; + // 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"}","${profileSalary.refId || "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`; - 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); - } + // 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); + // } }