import { Controller, Get, Post, Put, Delete, Route, Security, Tags, Body, Path, Request, Query, UploadedFile, } from "tsoa"; import { AppDataSource } from "../database/data-source"; import { Brackets, Double } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { UseInterceptors } from "@nestjs/common"; import { Profile } from "../entities/Profile"; import { FileInterceptor } from "@nestjs/platform-express"; import * as xlsx from "xlsx"; import { ProfileEducation } from "../entities/ProfileEducation"; import { ProfileSalary } from "../entities/ProfileSalary"; import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; import { ProfileFamilyMother } from "../entities/ProfileFamilyMother"; import { ProfileFamilyFather } from "../entities/ProfileFamilyFather"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { PosLevel } from "../entities/PosLevel"; import { PosType } from "../entities/PosType"; import Extension from "../interfaces/extension"; import { calculateAge, calculateRetireDate, calculateRetireLaw, calculateRetireYear, removeProfileInOrganize, } from "../interfaces/utils"; import * as fs from "fs"; import * as path from "path"; import csv from "csv-parser"; // src/importCsv.ts const { createConnection } = require("typeorm"); import csvParser from "csv-parser"; import { HR_POSITION_OFFICER } from "../entities/HR_POSITION_OFFICER"; import { HR_PERSONAL_OFFICER_FAMILY } from "../entities/HR_PERSONAL_OFFICER_FAMILY"; const BATCH_SIZE = 1000; // import { EducationMis } from "../entities/EducationMis"; @Route("api/v1/org/upload") @Tags("UPLOAD") @Security("bearerAuth") export class ImportDataController extends Controller { private educationRepository = AppDataSource.getRepository(ProfileEducation); private profileFamilyCoupleRepository = AppDataSource.getRepository(ProfileFamilyCouple); private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother); private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather); private salaryRepository = AppDataSource.getRepository(ProfileSalary); private profileRepo = AppDataSource.getRepository(Profile); private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private posLevelRepo = AppDataSource.getRepository(PosLevel); private posTypeRepo = AppDataSource.getRepository(PosType); private HR_POSITION_OFFICERRepo = AppDataSource.getRepository(HR_POSITION_OFFICER); private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_OFFICER_FAMILY); /** * @summary ทะเบียนประวัติ ข้าราชการ */ @Post("uploadProfile-Officer") async UploadFileSqlOfficer(@Request() request: { user: Record }) { let users = []; let rowCount = 0; const filePath = path.resolve(__dirname, "OFFICER.csv"); // Corrected file path const readStream = fs.createReadStream(filePath).pipe(csvParser()); let profiles: any = []; let null_: any = null; for await (const item of readStream) { // readStream.map(async (item: any) => { rowCount++; let type_: any = null; let level_: any = null; const profile = new Profile(); const existingProfile = await this.profileRepo.findOne({ where: { citizenId: item["ID"] }, }); if (existingProfile) { continue; } if (item["FLAG_RETIRE_STATUS"] != "" && item["FLAG_RETIRE_STATUS"] != null) { continue; } if (item["FLAG_PERSON_TYPE"] != "1") { continue; } if (item["MP_CEE_TYPE"]) { type_ = await this.posTypeRepo.findOne({ where: { posTypeName: item["MP_CEE_TYPE"] }, }); } if (item["MP_CEE_POSITION"]) { if (type_ == null) { level_ = await this.posLevelRepo.findOne({ where: { posLevelName: item["MP_CEE_POSITION"], }, }); } else { level_ = await this.posLevelRepo.findOne({ where: { posLevelName: item["MP_CEE_POSITION"], posTypeId: type_.id, }, }); } } let dateRetire = Extension.ConvertToDateTime(item["MP_FORCE_DATE"]); profile.citizenId = item["ID"] == "" ? "" : item["ID"]; profile.rank = item["RANK_NAME"] == "" ? null : item["RANK_NAME"]; profile.prefix = item["RANK_NAME"] == "" ? null : item["RANK_NAME"]; profile.firstName = item["FNAME"] == "" ? null : item["FNAME"]; profile.lastName = item["LNAME"] == "" ? null : item["LNAME"]; profile.gender = item["SEX"] == "1" ? "ชาย" : item["SEX"] == "2" ? "หญิง" : null_; profile.birthDate = item["BORN"] == "" ? null_ : Extension.ConvertToDateTime(item["BORN"]); profile.dateAppoint = item["BEGIN_ENTRY_DATE"] == "" ? null_ : Extension.ConvertToDateTime(item["BEGIN_ENTRY_DATE"]); profile.dateStart = item["MP_FORCE_DATE"] == "" ? null_ : Extension.ConvertToDateTime(item["MP_FORCE_DATE"]); profile.dateRetire = dateRetire == null ? null_ : calculateRetireDate(dateRetire); profile.dateRetireLaw = dateRetire == null ? null_ : calculateRetireLaw(dateRetire); profile.position = item["WORK_LINE_NAME"] == "" ? null : item["WORK_LINE_NAME"]; profile.posTypeId = type_ != null && type_.posTypeName == item["MP_CEE_TYPE"] && type_ ? type_.id : null; profile.posLevelId = level_ != null && level_.posLevelName == item["MP_CEE_POSITION"] && level_ ? level_.id : null; profile.relationship = item["MARRIAGE_STATE"] == "" ? "" : Extension.CheckRelationship(item["MARRIAGE_STATE"]); profile.isLeave = item["FLAG_RETIRE_STATUS"] == "" || item["FLAG_RETIRE_STATUS"] == null ? false : true; profile.createdUserId = request.user.sub; profile.createdFullName = request.user.name; profile.lastUpdateUserId = request.user.sub; profile.lastUpdateFullName = request.user.name; profiles.push(profile); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); if (profiles.length === BATCH_SIZE) { await this.profileRepo.save(profiles); profiles = []; if (global.gc) { global.gc(); } } } // ) // ); console.log(rowCount); await this.profileRepo.save(profiles); return new HttpSuccess(); } /** * @summary ทะเบียนประวัติ ลูกจ้างประจำ */ @Post("uploadProfile-Employee") async UploadFileSQL(@Request() request: { user: Record }) { let users = []; let rowCount = 0; const filePath = path.resolve(__dirname, "EMP.csv"); // Corrected file path const readStream = fs.createReadStream(filePath).pipe(csvParser()); let profiles: any = []; let null_: any = null; for await (const item of readStream) { rowCount++; const profileEmp = new ProfileEmployee(); const existingProfile = await this.profileEmpRepo.findOne({ where: { citizenId: item["ID"] }, }); console.log(item); console.log(item["ID"]); // console.log(existingProfile); if (existingProfile) { continue; } if (item["FLAG_PERSON_TYPE"] != "6") { continue; } let dateRetire = Extension.ConvertToDateTime(item["MP_FORCE_DATE"]); profileEmp.citizenId = item["ID"] == "" ? "" : item["ID"]; profileEmp.employeeClass = item["FLAG_PERSON_TYPE"] == "6" ? "PERM" : item["FLAG_PERSON_TYPE"] == "7" ? "TEMP" : ""; profileEmp.rank = item["RANK_NAME"] == "" ? null : item["RANK_NAME"]; profileEmp.prefix = item["RANK_NAME"] == "" ? null : item["RANK_NAME"]; profileEmp.firstName = item["FNAME"] == "" ? null : item["FNAME"]; profileEmp.lastName = item["LNAME"] == "" ? null : item["LNAME"]; profileEmp.gender = item["SEX"] == "1" ? "ชาย" : item["SEX"] == "2" ? "หญิง" : null_; profileEmp.birthDate = item["BORN"] == "" ? null_ : Extension.ConvertToDateTime(item["BORN"]); profileEmp.dateAppoint = item["BEGIN_ENTRY_DATE"] == "" ? null_ : Extension.ConvertToDateTime(item["BEGIN_ENTRY_DATE"]); profileEmp.dateStart = item["MP_FORCE_DATE"] == "" ? null_ : Extension.ConvertToDateTime(item["MP_FORCE_DATE"]); profileEmp.dateRetire = dateRetire == null ? null_ : calculateRetireDate(dateRetire); profileEmp.dateRetireLaw = dateRetire == null ? null_ : calculateRetireLaw(dateRetire); profileEmp.position = item["WORK_LINE_NAME"] == "" ? null : item["WORK_LINE_NAME"]; profileEmp.salaryLevel = item["SALARY_LEVEL_CODE"] == "" ? null : item["SALARY_LEVEL_CODE"]; profileEmp.relationship = item["MARRIAGE_STATE"] == "" ? "" : Extension.CheckRelationship(item["MARRIAGE_STATE"]); profileEmp.createdUserId = request.user.sub; profileEmp.createdFullName = request.user.name; profileEmp.lastUpdateUserId = request.user.sub; profileEmp.lastUpdateFullName = request.user.name; profiles.push(profileEmp); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); if (profiles.length === BATCH_SIZE) { await this.profileEmpRepo.save(profiles); profiles = []; if (global.gc) { global.gc(); } } } console.log(rowCount); await this.profileEmpRepo.save(profiles); return new HttpSuccess(); } /** * @summary เงินเดือน ข้าราชการ */ @Post("uploadProfileSalary-Officer") async UploadFileSQLSalary(@Request() request: { user: Record }) { let rowCount = 0; let profileSalarys: any = []; let null_: any = null; const [_profiles, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .select(["profile.id"]) .getManyAndCount(); for (var i = 1; i <= total / BATCH_SIZE; i++) { const profiles = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .select(["profile.citizenId", "profile.id"]) .orderBy("profile.citizenId", "ASC") .skip((i - 1) * BATCH_SIZE) .take(BATCH_SIZE) .getMany(); await Promise.all( profiles.map(async (_item) => { const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ where: { CIT: _item.citizenId }, select: [ "CIT", "MP_POS_DATE", "SALARY", "MP_COMMAND_NUM", "POS_NUM_NAME", "POS_NUM_CODE", "FLAG_TO_NAME", "WORK_LINE_NAME", "SPECIALIST_NAME", "ADMIN_NAME", "REMARK", "ORDER_MOVE_POSITION", ], }); profileSalarys = await []; await Promise.all( existingProfile.map(async (item) => { rowCount++; const profileSalary = new ProfileSalary(); profileSalary.date = item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); const SALARY: any = item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); profileSalary.amount = SALARY; profileSalary.profileId = _item.id; profileSalary.refCommandNo = item.MP_COMMAND_NUM; profileSalary.posNo = item.POS_NUM_NAME + item.POS_NUM_CODE; profileSalary.position = item.FLAG_TO_NAME; profileSalary.positionLine = item.WORK_LINE_NAME; profileSalary.positionPathSide = item.SPECIALIST_NAME; profileSalary.positionExecutive = item.ADMIN_NAME; profileSalary.templateDoc = item.REMARK; const ORDER_MOVE_POSITION: any = item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == "" ? null_ : Number(item.ORDER_MOVE_POSITION); profileSalary.order = ORDER_MOVE_POSITION; profileSalary.createdUserId = request.user.sub; profileSalary.createdFullName = request.user.name; profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateFullName = request.user.name; profileSalarys.push(profileSalary); }), ); await this.salaryRepository.save(profileSalarys); profileSalarys = []; }), ); } console.log(rowCount); return new HttpSuccess(profileSalarys); } /** * @summary เงินเดือน ลูกจ้างประจำ */ @Post("uploadProfileSalary-Employee") async UploadFileSQLSalaryEmp(@Request() request: { user: Record }) { let rowCount = 0; let profileSalarys: any = []; let null_: any = null; const [_profiles, total] = await AppDataSource.getRepository(ProfileEmployee) .createQueryBuilder("profile") .select(["profile.id"]) .getManyAndCount(); for (var i = 1; i <= total / BATCH_SIZE; i++) { const profiles = await AppDataSource.getRepository(ProfileEmployee) .createQueryBuilder("profile") .select(["profile.citizenId", "profile.id"]) .orderBy("profile.citizenId", "ASC") .skip((i - 1) * BATCH_SIZE) .take(BATCH_SIZE) .getMany(); await Promise.all( profiles.map(async (_item) => { const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ where: { CIT: _item.citizenId }, select: [ "CIT", "MP_POS_DATE", "SALARY", "MP_COMMAND_NUM", "POS_NUM_NAME", "POS_NUM_CODE", "FLAG_TO_NAME", "WORK_LINE_NAME", "SPECIALIST_NAME", "ADMIN_NAME", "REMARK", "ORDER_MOVE_POSITION", ], }); profileSalarys = await []; await Promise.all( existingProfile.map(async (item) => { rowCount++; const profileSalary = new ProfileSalary(); profileSalary.date = item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); const SALARY: any = item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); profileSalary.amount = SALARY; profileSalary.profileEmployeeId = _item.id; profileSalary.refCommandNo = item.MP_COMMAND_NUM; profileSalary.posNo = item.POS_NUM_NAME + item.POS_NUM_CODE; profileSalary.position = item.FLAG_TO_NAME; profileSalary.positionLine = item.WORK_LINE_NAME; profileSalary.positionPathSide = item.SPECIALIST_NAME; profileSalary.positionExecutive = item.ADMIN_NAME; profileSalary.templateDoc = item.REMARK; const ORDER_MOVE_POSITION: any = item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == "" ? null_ : Number(item.ORDER_MOVE_POSITION); profileSalary.order = ORDER_MOVE_POSITION; profileSalary.createdUserId = request.user.sub; profileSalary.createdFullName = request.user.name; profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateFullName = request.user.name; profileSalarys.push(profileSalary); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); }), ); await this.salaryRepository.save(profileSalarys); profileSalarys = []; }), ); } console.log(rowCount); await this.salaryRepository.save(profileSalarys); return new HttpSuccess(); } /** * @summary ครอบครัว ข้าราชการ */ @Post("uploadProfileFamily-Officer") async UploadFileSQLFamily(@Request() request: { user: Record }) { let rowCount = 0; let fathers: any = []; let mothers: any = []; let couples: any = []; const [_profiles, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .select(["profile.id"]) .getManyAndCount(); for (var i = 1; i <= total / BATCH_SIZE; i++) { const profiles = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .select(["profile.citizenId", "profile.id"]) .orderBy("profile.citizenId", "ASC") .skip((i - 1) * BATCH_SIZE) .take(BATCH_SIZE) .getMany(); await Promise.all( profiles.map(async (_item) => { const existingProfile = await this.HR_PERSONAL_OFFICER_FAMILYRepo.findOne({ where: { CIT: _item.citizenId }, select: [ "CIT", "FATHER_RANK_NAME", "FATHER_FNAME", "FATHER_LNAME", "MOTHER_RANK_NAME", "MOTHER_FNAME", "MOTHER_LNAME", "SPOUSE_RANK_NAME", "SPOUSE_FNAME", "SPOUSE_LNAME", "SPOUSE_ID", "MARRIAGE_STATE", ], }); if (!existingProfile) { return; } // fathers = await []; // mothers = await []; // couples = await []; // await Promise.all( // existingProfile.map(async (item) => { rowCount++; const profileFather = new ProfileFamilyFather(); const profileMother = new ProfileFamilyMother(); const profileCouple = new ProfileFamilyCouple(); profileFather.profileId = _item.id; profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; profileFather.fatherFirstName = existingProfile.FATHER_FNAME; profileFather.fatherLastName = existingProfile.FATHER_LNAME; profileFather.createdUserId = request.user.sub; profileFather.createdFullName = request.user.name; profileFather.lastUpdateUserId = request.user.sub; profileFather.lastUpdateFullName = request.user.name; profileMother.profileId = _item.id; profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; profileMother.motherFirstName = existingProfile.MOTHER_FNAME; profileMother.motherLastName = existingProfile.MOTHER_LNAME; profileMother.createdUserId = request.user.sub; profileMother.createdFullName = request.user.name; profileMother.lastUpdateUserId = request.user.sub; profileMother.lastUpdateFullName = request.user.name; profileCouple.profileId = _item.id; profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; profileCouple.relationship = existingProfile.MARRIAGE_STATE; // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; profileCouple.createdUserId = request.user.sub; profileCouple.createdFullName = request.user.name; profileCouple.lastUpdateUserId = request.user.sub; profileCouple.lastUpdateFullName = request.user.name; fathers.push(profileFather); mothers.push(profileMother); couples.push(profileCouple); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); if (fathers.length === BATCH_SIZE) { await this.profileFamilyFatherRepository.save(fathers); fathers = await []; // if (global.gc) { // global.gc(); // } } if (mothers.length === BATCH_SIZE) { await this.profileFamilyMotherRepository.save(mothers); mothers = await []; // if (global.gc) { // global.gc(); // } } if (couples.length === BATCH_SIZE) { await this.profileFamilyCoupleRepository.save(couples); couples = await []; // if (global.gc) { // global.gc(); // } } // }), // ); // await this.salaryRepository.save(profileSalarys); // profileSalarys = []; }), ); } // } console.log(rowCount); await Promise.all([ this.profileFamilyFatherRepository.save(fathers), this.profileFamilyMotherRepository.save(mothers), this.profileFamilyCoupleRepository.save(couples), ]); return new HttpSuccess(); } /** * @summary ครอบครัว ลูกจ้างประจำ */ @Post("uploadProfileFamily-Employee") async UploadFileSQLFamilyEmp(@Request() request: { user: Record }) { let rowCount = 0; let fathers: any = []; let mothers: any = []; let couples: any = []; const [_profiles, total] = await AppDataSource.getRepository(ProfileEmployee) .createQueryBuilder("profile") .select(["profile.id"]) .getManyAndCount(); for (var i = 1; i <= total / BATCH_SIZE; i++) { const profiles = await AppDataSource.getRepository(ProfileEmployee) .createQueryBuilder("profile") .select(["profile.citizenId", "profile.id"]) .orderBy("profile.citizenId", "ASC") .skip((i - 1) * BATCH_SIZE) .take(BATCH_SIZE) .getMany(); await Promise.all( profiles.map(async (_item) => { const existingProfile = await this.HR_PERSONAL_OFFICER_FAMILYRepo.findOne({ where: { CIT: _item.citizenId }, select: [ "CIT", "FATHER_RANK_NAME", "FATHER_FNAME", "FATHER_LNAME", "MOTHER_RANK_NAME", "MOTHER_FNAME", "MOTHER_LNAME", "SPOUSE_RANK_NAME", "SPOUSE_FNAME", "SPOUSE_LNAME", "SPOUSE_ID", "MARRIAGE_STATE", ], }); if (!existingProfile) { return; } rowCount++; const profileFather = new ProfileFamilyFather(); const profileMother = new ProfileFamilyMother(); const profileCouple = new ProfileFamilyCouple(); profileFather.profileEmployeeId = _item.id; profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; profileFather.fatherFirstName = existingProfile.FATHER_FNAME; profileFather.fatherLastName = existingProfile.FATHER_LNAME; profileFather.createdUserId = request.user.sub; profileFather.createdFullName = request.user.name; profileFather.lastUpdateUserId = request.user.sub; profileFather.lastUpdateFullName = request.user.name; profileMother.profileEmployeeId = _item.id; profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; profileMother.motherFirstName = existingProfile.MOTHER_FNAME; profileMother.motherLastName = existingProfile.MOTHER_LNAME; profileMother.createdUserId = request.user.sub; profileMother.createdFullName = request.user.name; profileMother.lastUpdateUserId = request.user.sub; profileMother.lastUpdateFullName = request.user.name; profileCouple.profileEmployeeId = _item.id; profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; profileCouple.relationship = existingProfile.MARRIAGE_STATE; // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; profileCouple.createdUserId = request.user.sub; profileCouple.createdFullName = request.user.name; profileCouple.lastUpdateUserId = request.user.sub; profileCouple.lastUpdateFullName = request.user.name; fathers.push(profileFather); mothers.push(profileMother); couples.push(profileCouple); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); if (fathers.length === BATCH_SIZE) { await this.profileFamilyFatherRepository.save(fathers); fathers = await []; } if (mothers.length === BATCH_SIZE) { await this.profileFamilyMotherRepository.save(mothers); mothers = await []; } if (couples.length === BATCH_SIZE) { await this.profileFamilyCoupleRepository.save(couples); couples = await []; } }), ); } console.log(rowCount); await Promise.all([ this.profileFamilyFatherRepository.save(fathers), this.profileFamilyMotherRepository.save(mothers), this.profileFamilyCoupleRepository.save(couples), ]); return new HttpSuccess(); } // /** // * @summary Import Education Code // */ // @Post("uploadEducation-Code") // @UseInterceptors(FileInterceptor("file")) // async UploadFileSQLEducationCode( // @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, // ) { // const workbook = xlsx.read(file.buffer, { type: "buffer" }); // const sheetName = workbook.SheetNames[0] // const sheet = workbook.Sheets[sheetName]; // const getExcel = xlsx.utils.sheet_to_json(sheet); // let educationMis_: any = []; // await Promise.all( // getExcel.map(async (item: any) => { // const educationMis = new EducationMis(); // educationMis.EDUCATION_CODE = item.EDUCATION_CODE; // educationMis.EDUCATION_CODE = item.EDUCATION_CODE; // educationMis_.push(educationMis); // }), // ); // await this.educationMisRepo.save(educationMis_); // return new HttpSuccess(educationMis_); // } // /** // * API upload EDU // * // * @summary DEV_0 - upload EDU # // * // */ // @Post("") // @UseInterceptors(FileInterceptor("file")) // async UploadUserDevelopemtById(@UploadedFile() file: Express.Multer.File) { // const workbook = xlsx.read(file.buffer, { type: "buffer" }); // const sheetName = workbook.SheetNames[1]; // const sheet = workbook.Sheets[sheetName]; // const getEducations = xlsx.utils.sheet_to_json(sheet); // await Promise.all( // getEducations.map(async (item: any) => { // if (item["id"] === undefined) { // return; // } // const education = new ProfileEducation(); // education.id = item["id"]; // education.createdAt = item["createdAt"]; // education.createdUserId = item["createdUserId"]; // education.lastUpdatedAt = item["lastUpdatedAt"]; // education.lastUpdateUserId = item["lastUpdateUserId"]; // education.createdFullName = item["createdFullName"]; // education.lastUpdateFullName = item["lastUpdateFullName"]; // education.profileId = item["profileId"]; // education.country = item["country"]; // education.degree = item["degree"]; // education.duration = item["duration"]; // education.durationYear = item["durationYear"]; // education.field = item["field"]; // education.finishDate = item["finishDate"]; // education.fundName = item["fundName"]; // education.institute = item["institute"]; // education.other = item["other"]; // education.startDate = item["startDate"]; // education.endDate = item["endDate"]; // education.educationLevel = item["educationLevel"]; // education.educationLevelId = item["educationLevelId"]; // education.positionPath = item["positionPath"]; // education.positionPathId = item["positionPathId"]; // education.isDate = item["isDate"]; // education.isEducation = item["isEducation"]; // education.note = item["note"]; // education.profileEmployeeId = item["profileEmployeeId"]; // await this.educationRepository.save(education); // }), // ); // } // @Post("uploadSQLEdu") // @UseInterceptors(FileInterceptor("file")) // async UploadFileSQLEdu( // @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, // ) { // const workbook = xlsx.read(file.buffer, { type: "buffer" }); // const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet // const sheet = workbook.Sheets[sheetName]; // const getProFile = xlsx.utils.sheet_to_json(sheet); // let profiles: any = []; // await Promise.all( // getProFile.map(async (item: any) => { // // Create a new Profile entity and assign fields from the parsed data // const profile = new ProfileEducation(); // // Check if the profile already exists // const existingProfile = await this.educationRepository.findOne({ // where: { id: item["id"] }, // }); // // If profile exists, skip saving // if (existingProfile) { // return; // } // // Assign fields from the item to the profile entit // profile.id = item["id"] == "NULL" ? null : item["id"]; // // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); // profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // // profile.lastUpdatedAt = // // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); // profile.lastUpdateUserId = // item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; // profile.createdFullName = // item["createdFullName"] == "NULL" ? null : item["createdFullName"]; // profile.lastUpdateFullName = // item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; // profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; // profile.country = item["country"] == "NULL" ? null : item["country"]; // profile.degree = item["degree"] == "NULL" ? null : item["degree"]; // profile.duration = item["duration"] == "NULL" ? null : item["duration"]; // profile.durationYear = item["durationYear"] == "NULL" ? null : item["durationYear"]; // profile.field = item["field"] == "NULL" ? null : item["field"]; // // profile.finishDate = item["finishDate"] == "NULL" ? null : new Date(item["finishDate"]); // profile.fundName = item["fundName"] == "NULL" ? null : item["fundName"]; // profile.gpa = item["gpa"] == "NULL" ? null : item["gpa"]; // profile.institute = item["institute"] == "NULL" ? null : item["institute"]; // profile.other = item["other"] == "NULL" ? null : item["other"]; // // profile.startDate = item["startDate"] == "NULL" ? null : new Date(item["startDate"]); // // profile.endDate = item["endDate"] == "NULL" ? null : new Date(item["endDate"]); // profile.educationLevel = item["educationLevel"] == "NULL" ? null : item["educationLevel"]; // profile.educationLevelId = // item["educationLevelId"] == "NULL" ? null : item["educationLevelId"]; // profile.positionPath = item["positionPath"] == "NULL" ? null : item["positionPath"]; // profile.positionPathId = item["positionPathId"] == "NULL" ? null : item["positionPathId"]; // profile.isDate = item["isDate"] == "NULL" ? null : item["isDate"]; // profile.isEducation = item["isEducation"] == "NULL" ? null : item["isEducation"]; // profile.note = item["note"] == "NULL" ? null : item["note"]; // profile.profileEmployeeId = // item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; // profiles.push(profile); // }), // ); // await this.educationRepository.save(profiles); // return new HttpSuccess(getProFile); // } // @Post("uploadSQLFamilly-Father") // @UseInterceptors(FileInterceptor("file")) // async UploadFileSQLFamilly( // @UploadedFile() file: Express.Multer.File, // // @Request() request: { user: Record }, // ) { // const workbook = xlsx.read(file.buffer, { type: "buffer" }); // const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet // const sheet = workbook.Sheets[sheetName]; // const getProFile = xlsx.utils.sheet_to_json(sheet); // let profiles: any = []; // await Promise.all( // getProFile.map(async (item: any) => { // // Create a new Profile entity and assign fields from the parsed data // const profile = new ProfileFamilyFather(); // // Check if the profile already exists // const existingProfile = await this.profileFamilyFatherRepository.findOne({ // where: { id: item["id"] }, // }); // // If profile exists, skip saving // if (existingProfile) { // return; // } // // Assign fields from the item to the profile entit // profile.id = item["id"] == "NULL" ? null : item["id"]; // // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); // profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // // profile.lastUpdatedAt = // // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); // profile.lastUpdateUserId = // item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; // profile.createdFullName = // item["createdFullName"] == "NULL" ? null : item["createdFullName"]; // profile.lastUpdateFullName = // item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; // profile.fatherPrefix = item["fatherPrefix"] == "NULL" ? null : item["fatherPrefix"]; // profile.fatherFirstName = // item["fatherFirstName"] == "NULL" ? null : item["fatherFirstName"]; // profile.fatherLastName = item["fatherLastName"] == "NULL" ? null : item["fatherLastName"]; // profile.fatherCareer = item["fatherCareer"] == "NULL" ? null : item["fatherCareer"]; // profile.fatherCitizenId = // item["fatherCitizenId"] == "NULL" ? null : item["fatherCitizenId"]; // profile.fatherLive = item["fatherLive"] == "NULL" ? null : item["fatherLive"]; // profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; // profile.profileEmployeeId = // item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; // profiles.push(profile); // }), // ); // await this.profileFamilyFatherRepository.save(profiles); // return new HttpSuccess(getProFile); // } // @Post("uploadSQLFamilly-Mother") // @UseInterceptors(FileInterceptor("file")) // async UploadFileSQLFamillyMother( // @UploadedFile() file: Express.Multer.File, // @Request() request: { user: Record }, // ) { // const workbook = xlsx.read(file.buffer, { type: "buffer" }); // const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet // const sheet = workbook.Sheets[sheetName]; // const getProFile = xlsx.utils.sheet_to_json(sheet); // let profiles: any = []; // await Promise.all( // getProFile.map(async (item: any) => { // // Create a new Profile entity and assign fields from the parsed data // const profile = new ProfileFamilyMother(); // // Check if the profile already exists // const existingProfile = await this.profileFamilyMotherRepository.findOne({ // where: { id: item["id"] }, // }); // // If profile exists, skip saving // if (existingProfile) { // return; // } // // Assign fields from the item to the profile entit // profile.id = item["id"] == "NULL" ? null : item["id"]; // // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); // profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // // profile.lastUpdatedAt = // // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); // profile.lastUpdateUserId = // item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; // profile.createdFullName = // item["createdFullName"] == "NULL" ? null : item["createdFullName"]; // profile.lastUpdateFullName = // item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; // profile.motherPrefix = item["motherPrefix"] == "NULL" ? null : item["motherPrefix"]; // profile.motherFirstName = // item["motherFirstName"] == "NULL" ? null : item["motherFirstName"]; // profile.motherLastName = item["motherLastName"] == "NULL" ? null : item["motherLastName"]; // profile.motherCareer = item["motherCareer"] == "NULL" ? null : item["motherCareer"]; // profile.motherCitizenId = // item["motherCitizenId"] == "NULL" ? null : item["motherCitizenId"]; // profile.motherLive = item["motherLive"] == "NULL" ? null : item["motherLive"]; // profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; // profile.profileEmployeeId = // item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; // profiles.push(profile); // }), // ); // await this.profileFamilyMotherRepository.save(profiles); // return new HttpSuccess(getProFile); // } // @Post("uploadSQLFamilly-Couple") // @UseInterceptors(FileInterceptor("file")) // async UploadFileSQLFamillyCouple( // @UploadedFile() file: Express.Multer.File, // // @Request() request: { user: Record }, // ) { // const workbook = xlsx.read(file.buffer, { type: "buffer" }); // const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet // const sheet = workbook.Sheets[sheetName]; // const getProFile = xlsx.utils.sheet_to_json(sheet); // let profiles: any = []; // await Promise.all( // getProFile.map(async (item: any) => { // // Create a new Profile entity and assign fields from the parsed data // const profile = new ProfileFamilyCouple(); // // Check if the profile already exists // const existingProfile = await this.profileFamilyCoupleRepository.findOne({ // where: { id: item["id"] }, // }); // // If profile exists, skip saving // if (existingProfile) { // return; // } // // Assign fields from the item to the profile entit // profile.id = item["id"] == "NULL" ? null : item["id"]; // // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); // profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; // // profile.lastUpdatedAt = // // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); // profile.lastUpdateUserId = // item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; // profile.createdFullName = // item["createdFullName"] == "NULL" ? null : item["createdFullName"]; // profile.lastUpdateFullName = // item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; // profile.couple = item["couple"] == "NULL" ? null : item["couple"]; // profile.couplePrefix = item["couplePrefix"] == "NULL" ? null : item["couplePrefix"]; // profile.coupleFirstName = // item["coupleFirstName"] == "NULL" ? null : item["coupleFirstName"]; // profile.coupleLastName = item["coupleLastName"] == "NULL" ? null : item["coupleLastName"]; // profile.coupleLastNameOld = // item["coupleLastNameOld"] == "NULL" ? null : item["coupleLastNameOld"]; // profile.coupleCareer = item["coupleCareer"] == "NULL" ? null : item["coupleCareer"]; // profile.coupleCitizenId = // item["coupleCitizenId"] == "NULL" ? null : item["coupleCitizenId"]; // profile.coupleLive = item["coupleLive"] == "NULL" ? null : item["coupleLive"]; // profile.relationship = item["relationship"] == "NULL" ? null : item["relationship"]; // profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; // profile.profileEmployeeId = // item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; // profiles.push(profile); // }), // ); // await this.profileFamilyCoupleRepository.save(profiles); // return new HttpSuccess(getProFile); // } }