hrms-api-org/src/controllers/ImportDataController.ts
2024-07-25 16:27:43 +07:00

755 lines
34 KiB
TypeScript

import {
Controller,
Get,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
Query,
UploadedFile,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { Brackets } 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 { 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 educationMisRepo = AppDataSource.getRepository(EducationMis);
/**
* @summary ทะเบียนประวัติ ข้าราชการ
*/
@Post("uploadProfile-Officer")
@UseInterceptors(FileInterceptor("file"))
async UploadFileSqlOfficer(
@UploadedFile() file: Express.Multer.File,
@Request() request: { user: Record<string, any> },
) {
const workbook = xlsx.read(file.buffer, { type: "buffer" });
const sheetName = workbook.SheetNames[0];
const sheet = workbook.Sheets[sheetName];
const getProFile = xlsx.utils.sheet_to_json(sheet);
let profiles: any = [];
let null_: any = null;
await Promise.all(
getProFile.map(async (item: any) => {
let type_: any = null;
let level_: any = null;
let dateRetire: any = null;
const profile = new Profile();
const existingProfile = await this.profileRepo.findOne({
where: { citizenId: item["ID"] },
});
if (existingProfile) {
return;
}
if(item["MP_CEE_TYPE"]) {
type_ = await this.posTypeRepo.findOne({
where: { posTypeName: item["MP_CEE_TYPE"] }
})
}
if(item["MP_CEE_POSITION"]) {
level_ = await this.posLevelRepo.findOne({
where: {
posLevelName: item["MP_CEE_POSITION"],
posTypeId: type_.id
}
})
}
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_.id : null;
profile.posLevelId = level_ != null && level_.posLevelName == item["MP_CEE_POSITION"] ? 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);
}),
);
await this.profileRepo.save(profiles);
return new HttpSuccess();
}
/**
* @summary ทะเบียนประวัติ ลูกจ้างประจำ
*/
@Post("uploadProfile-Employee")
@UseInterceptors(FileInterceptor("file"))
async UploadFileSQL(
@UploadedFile() file: Express.Multer.File,
@Request() request: { user: Record<string, any> },
) {
const workbook = xlsx.read(file.buffer, { type: "buffer" });
const sheetName = workbook.SheetNames[0];
const sheet = workbook.Sheets[sheetName];
const getProFile = xlsx.utils.sheet_to_json(sheet);
let profiles: any = [];
let null_: any = null
let dateRetire: any = null;
await Promise.all(
getProFile.map(async (item: any) => {
const profileEmp = new ProfileEmployee();
const existingProfile = await this.profileEmpRepo.findOne({
where: { citizenId: item["ID"] },
});
if (existingProfile) {
return;
}
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);
}),
);
await this.profileEmpRepo.save(profiles);
return new HttpSuccess();
}
/**
* @summary เงินเดือน ข้าราชการ
*/
@Post("uploadProfileSalary-Officer")
@UseInterceptors(FileInterceptor("file"))
async UploadFileSQLSalary(
@UploadedFile() file: Express.Multer.File,
@Request() request: { user: Record<string, any> },
) {
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 profileSalarys: any = [];
let null_: any=null
await Promise.all(
getExcel
.filter((x:any) => x.FLAG_PERSON_TYPE == 1)
.map(async (item: any) => {
const profileSalary = new ProfileSalary();
const existingProfile = await this.profileRepo.findOne({
where: { citizenId: item.ID },
});
if (!existingProfile) {
return;
}
profileSalary.date = item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE);
profileSalary.amount = item.SALARY;
profileSalary.profileId = existingProfile.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;
profileSalary.order = item.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);
return new HttpSuccess();
}
/**
* @summary เงินเดือน ลูกจ้างประจำ
*/
@Post("uploadProfileSalary-Employee")
@UseInterceptors(FileInterceptor("file"))
async UploadFileSQLSalaryEmp(
@UploadedFile() file: Express.Multer.File,
@Request() request: { user: Record<string, any> },
) {
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 profileSalarys: any = [];
let null_: any=null
await Promise.all(
getExcel
.filter((x:any) => x.FLAG_PERSON_TYPE == 6)
.map(async (item: any) => {
const profileSalary = new ProfileSalary();
const existingProfile = await this.profileEmpRepo.findOne({
where: { citizenId: item.ID },
});
if (!existingProfile) {
return;
}
profileSalary.date = item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE);
profileSalary.amount = item.SALARY;
profileSalary.profileEmployeeId = existingProfile.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;
profileSalary.order = item.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);
return new HttpSuccess();
}
/**
* @summary ครอบครัว ข้าราชการ
*/
@Post("uploadProfileFamily-Officer")
@UseInterceptors(FileInterceptor("file"))
async UploadFileSQLFamily(
@UploadedFile() file: Express.Multer.File,
@Request() request: { user: Record<string, any> },
) {
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 fathers: any = [];
let mothers: any = [];
let couples: any = [];
let null_: any = null
await Promise.all(
getExcel.map(async (item: any) => {
const profileFather = new ProfileFamilyFather();
const profileMother = new ProfileFamilyMother();
const profileCouple = new ProfileFamilyCouple();
const existingProfile = await this.profileRepo.findOne({
where: { citizenId: item.ID },
});
if (!existingProfile) {
return;
}
profileFather.profileId = existingProfile.id;
profileFather.fatherPrefix = item.FATHER_RANK_NAME;
profileFather.fatherFirstName = item.FATHER_FNAME;
profileFather.fatherLastName = item.FATHER_LNAME;
profileFather.createdUserId = request.user.sub;
profileFather.createdFullName = request.user.name;
profileFather.lastUpdateUserId = request.user.sub;
profileFather.lastUpdateFullName = request.user.name
profileMother.profileId = existingProfile.id;
profileMother.motherPrefix = item.MOTHER_RANK_NAME;
profileMother.motherFirstName = item.MOTHER_FNAME;
profileMother.motherLastName = item.MOTHER_LNAME;
profileMother.createdUserId = request.user.sub;
profileMother.createdFullName = request.user.name;
profileMother.lastUpdateUserId = request.user.sub;
profileMother.lastUpdateFullName = request.user.name
profileCouple.profileId = existingProfile.id;
profileCouple.couplePrefix = item.SPOUSE_RANK_NAME;
profileCouple.coupleFirstName = item.SPOUSE_FNAME;
profileCouple.coupleLastName = item.SPOUSE_LNAME;
profileCouple.coupleCitizenId = item.SPOUSE_ID;
profileCouple.relationship = item.MARRIAGE_STATE;
profileCouple.coupleLive = item.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);
}),
);
const result = {
fathers: fathers,
mothers: mothers,
couples: couples,
};
await Promise.all([
this.profileFamilyFatherRepository.save(fathers),
this.profileFamilyMotherRepository.save(mothers),
this.profileFamilyCoupleRepository.save(couples)
]);
return new HttpSuccess();
}
/**
* @summary ครอบครัว ลูกจ้างประจำ
*/
@Post("uploadProfileFamily-Employee")
@UseInterceptors(FileInterceptor("file"))
async UploadFileSQLFamilyEmp(
@UploadedFile() file: Express.Multer.File,
@Request() request: { user: Record<string, any> },
) {
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 fathers: any = [];
let mothers: any = [];
let couples: any = [];
let null_: any = null
await Promise.all(
getExcel.map(async (item: any) => {
const profileFather = new ProfileFamilyFather();
const profileMother = new ProfileFamilyMother();
const profileCouple = new ProfileFamilyCouple();
const existingProfile = await this.profileEmpRepo.findOne({
where: { citizenId: item.ID },
});
if (!existingProfile) {
return;
}
profileFather.profileEmployeeId = existingProfile.id;
profileFather.fatherPrefix = item.FATHER_RANK_NAME;
profileFather.fatherFirstName = item.FATHER_FNAME;
profileFather.fatherLastName = item.FATHER_LNAME;
profileFather.createdUserId = request.user.sub;
profileFather.createdFullName = request.user.name;
profileFather.lastUpdateUserId = request.user.sub;
profileFather.lastUpdateFullName = request.user.name
profileMother.profileEmployeeId = existingProfile.id;
profileMother.motherPrefix = item.MOTHER_RANK_NAME;
profileMother.motherFirstName = item.MOTHER_FNAME;
profileMother.motherLastName = item.MOTHER_LNAME;
profileMother.createdUserId = request.user.sub;
profileMother.createdFullName = request.user.name;
profileMother.lastUpdateUserId = request.user.sub;
profileMother.lastUpdateFullName = request.user.name
profileCouple.profileEmployeeId = existingProfile.id;
profileCouple.couplePrefix = item.SPOUSE_RANK_NAME;
profileCouple.coupleFirstName = item.SPOUSE_FNAME;
profileCouple.coupleLastName = item.SPOUSE_LNAME;
profileCouple.coupleCitizenId = item.SPOUSE_ID;
profileCouple.relationship = item.MARRIAGE_STATE;
profileCouple.coupleLive = item.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);
}),
);
const result = {
fathers: fathers,
mothers: mothers,
couples: couples,
};
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<string, any> },
// ) {
// 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<string, any> },
// ) {
// 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<string, any> },
// ) {
// 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<string, any> },
// ) {
// 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<string, any> },
// ) {
// 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);
// }
}