diff --git a/package-lock.json b/package-lock.json index c2d3cc29..4b20d91a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "dotenv": "^16.3.1", "express": "^4.18.2", "fast-jwt": "^3.3.2", + "moment": "^2.30.1", "mysql2": "^3.9.1", "node-cron": "^3.0.3", "node-xlsx": "^0.24.0", @@ -2877,6 +2878,14 @@ "obliterator": "^2.0.1" } }, + "node_modules/moment": { + "version": "2.30.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", + "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", diff --git a/package.json b/package.json index 6a7eb347..e950b983 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "dotenv": "^16.3.1", "express": "^4.18.2", "fast-jwt": "^3.3.2", + "moment": "^2.30.1", "mysql2": "^3.9.1", "node-cron": "^3.0.3", "node-xlsx": "^0.24.0", diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index f9230ec8..04cd00bb 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -30,6 +30,15 @@ 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") @@ -44,612 +53,703 @@ export class ImportDataController extends Controller { private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private posLevelRepo = AppDataSource.getRepository(PosLevel); private posTypeRepo = AppDataSource.getRepository(PosType); + private educationMisRepo = AppDataSource.getRepository(EducationMis); + /** - * API upload EDU - * - * @summary DEV_0 - upload EDU # - * + * @summary ทะเบียนประวัติ ข้าราชการ */ - @Post("") + @Post("uploadProfile-Officer") @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); - }), - ); - } - /** - * - * @param id - * @param file - * @param request - * @returns - */ - @Post("uploadSQL") - @UseInterceptors(FileInterceptor("file")) - async UploadFileSQL( + async UploadFileSqlOfficer( @UploadedFile() file: Express.Multer.File, - // @Request() request: { user: Record }, + @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 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) => { - // Create a new Profile entity and assign fields from the parsed data - - const profile = new ProfileEmployee(); - // Check if the profile already exists - const existingProfile = await this.profileEmpRepo.findOne({ - where: { id: item["id"] }, + 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 profile exists, skip saving if (existingProfile) { return; } - // Assign fields from the item to the profile entity - profile.id = item["id"]; - // profile.createdAt = item["createdUserId"] == "NULL" ? null : new Date(item["createdAt"]); - profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; - // profile.lastUpdatedAt = - // item["createdUserId"] == "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.prefix = item["prefix"] == "NULL" ? null : item["prefix"]; - profile.firstName = item["firstName"] == "NULL" ? null : item["firstName"]; - profile.lastName = item["lastName"] == "NULL" ? null : item["lastName"]; - profile.citizenId = item["citizenId"] == "NULL" ? null : item["citizenId"]; - profile.position = item["position"] == "NULL" ? null : item["position"]; - profile.posLevelId = item["posLevelId"] == "NULL" ? null : item["posLevelId"]; - profile.posTypeId = item["posTypeId"] == "NULL" ? null : item["posTypeId"]; - profile.email = item["email"] == "NULL" ? null : item["email"]; - profile.phone = item["phone"] == "NULL" ? null : item["phone"]; - profile.keycloak = item["keycloak"] == "NULL" ? null : item["keycloak"]; - profile.isProbation = item["isProbation"] == "NULL" ? null : item["isProbation"]; - // profile.dateRetire = item["dateRetire"] == "NULL" ? null : new Date(item["dateRetire"]); - // profile.birthDate = item["birthDate"] == "NULL" ? null : new Date(item["birthDate"]); - profile.salaryLevel = item["salaryLevel"] == "NULL" ? null : item["salaryLevel"]; - profile.ethnicity = item["ethnicity"] == "NULL" ? null : item["ethnicity"]; - profile.telephoneNumber = - item["telephoneNumber"] == "NULL" ? null : item["telephoneNumber"]; - profile.group = item["group"] == "NULL" ? null : item["group"]; - profile.gender = item["gender"] == "NULL" ? null : item["gender"]; - profile.relationship = item["relationship"] == "NULL" ? null : item["relationship"]; - profile.religion = item["religion"] == "NULL" ? null : item["religion"]; - profile.bloodGroup = item["bloodGroup"] == "NULL" ? null : item["bloodGroup"]; - profile.rank = item["rank"] == "NULL" ? null : item["rank"]; - profile.employeeClass = item["employeeClass"] == "NULL" ? null : item["employeeClass"]; - profile.avatar = item["avatar"] == "NULL" ? null : item["avatar"]; - // profile.dateRetireLaw = - // item["dateRetireLaw"] == "NULL" ? null : new Date(item["dateRetireLaw"]); - profile.registrationAddress = - item["registrationAddress"] == "NULL" ? null : item["registrationAddress"]; - profile.registrationProvinceId = - item["registrationProvinceId"] == "NULL" ? null : item["registrationProvinceId"]; - profile.registrationDistrictId = - item["registrationDistrictId"] == "NULL" ? null : item["registrationDistrictId"]; - profile.registrationSubDistrictId = - item["registrationSubDistrictId"] == "NULL" ? null : item["registrationSubDistrictId"]; - profile.registrationZipCode = - item["registrationZipCode"] == "NULL" ? null : item["registrationZipCode"]; - profile.currentAddress = item["currentAddress"] == "NULL" ? null : item["currentAddress"]; - profile.currentProvinceId = - item["currentProvinceId"] == "NULL" ? null : item["currentProvinceId"]; - profile.currentDistrictId = - item["currentDistrictId"] == "NULL" ? null : item["currentDistrictId"]; - profile.currentSubDistrictId = - item["currentSubDistrictId"] == "NULL" ? null : item["currentSubDistrictId"]; - profile.currentZipCode = item["currentZipCode"] == "NULL" ? null : item["currentZipCode"]; - profile.avatarName = item["avatarName"] == "NULL" ? null : item["avatarName"]; - profile.nationality = item["nationality"] == "NULL" ? null : item["nationality"]; - // profile.dateAppoint = item["dateAppoint"] == "NULL" ? null : new Date(item["dateAppoint"]); - // profile.dateStart = item["dateStart"] == "NULL" ? null : new Date(item["dateStart"]); - profile.govAgeAbsent = item["govAgeAbsent"] == "NULL" ? null : item["govAgeAbsent"]; - profile.govAgePlus = item["govAgePlus"] == "NULL" ? null : item["govAgePlus"]; - profile.reasonSameDate = item["reasonSameDate"] == "NULL" ? null : item["reasonSameDate"]; + 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(getProFile); + } + + /** + * @summary ทะเบียนประวัติ ลูกจ้างประจำ + */ + @Post("uploadProfile-Employee") + @UseInterceptors(FileInterceptor("file")) + async UploadFileSQL( + @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 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(getProFile); } - @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("uploadSQL-Officer") - @UseInterceptors(FileInterceptor("file")) - async UploadFileSqlOfficer( - @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 Profile(); - // Check if the profile already exists - const existingProfile = await this.profileRepo.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.prefix = item["prefix"] == "NULL" ? null : item["prefix"]; - profile.firstName = item["firstName"] == "NULL" ? null : item["firstName"]; - profile.lastName = item["lastName"] == "NULL" ? null : item["lastName"]; - profile.citizenId = item["citizenId"] == "NULL" ? null : item["citizenId"]; - profile.position = item["position"] == "NULL" ? null : item["position"]; - profile.posTypeId = item["posTypeId"] == "NULL" ? null : item["posTypeId"]; - profile.posLevelId = item["posLevelId"] == "NULL" ? null : item["posLevelId"]; - profile.keycloak = item["keycloak"] == "NULL" ? null : item["keycloak"]; - profile.email = item["email"] == "NULL" ? null : item["email"]; - profile.phone = item["phone"] == "NULL" ? null : item["phone"]; - profile.isProbation = item["isProbation"] == "NULL" ? null : item["isProbation"]; - // profile.dateRetire = item["dateRetire"] == "NULL" ? null : new Date(item["dateRetire"]); - // profile.birthDate = item["birthDate"] == "NULL" ? null : new Date(item["birthDate"]); - profile.rank = item["rank"] == "NULL" ? null : item["rank"]; - profile.isLeave = item["isLeave"] == "NULL" ? null : item["isLeave"]; - // profile.dateAppoint = item["dateAppoint"] == "NULL" ? null : new Date(item["dateAppoint"]); - // profile.dateStart = item["dateStart"] == "NULL" ? null : new Date(item["dateStart"]); - profile.govAgeAbsent = item["govAgeAbsent"] == "NULL" ? null : item["govAgeAbsent"]; - profile.govAgePlus = item["govAgePlus"] == "NULL" ? null : item["govAgePlus"]; - profile.reasonSameDate = item["reasonSameDate"] == "NULL" ? null : item["reasonSameDate"]; - profile.ethnicity = item["ethnicity"] == "NULL" ? null : item["ethnicity"]; - profile.telephoneNumber = - item["telephoneNumber"] == "NULL" ? null : item["telephoneNumber"]; - profile.nationality = item["nationality"] == "NULL" ? null : item["nationality"]; - profile.gender = item["gender"] == "NULL" ? null : item["gender"]; - profile.relationship = item["relationship"] == "NULL" ? null : item["relationship"]; - profile.religion = item["religion"] == "NULL" ? null : item["religion"]; - profile.bloodGroup = item["bloodGroup"] == "NULL" ? null : item["bloodGroup"]; - profile.registrationAddress = - item["registrationAddress"] == "NULL" ? null : item["registrationAddress"]; - profile.registrationProvinceId = - item["registrationProvinceId"] == "NULL" ? null : item["registrationProvinceId"]; - profile.registrationDistrictId = - item["registrationDistrictId"] == "NULL" ? null : item["registrationDistrictId"]; - profile.registrationSubDistrictId = - item["registrationSubDistrictId"] == "NULL" ? null : item["registrationSubDistrictId"]; - profile.registrationZipCode = - item["registrationZipCode"] == "NULL" ? null : item["registrationZipCode"]; - profile.currentAddress = item["currentAddress"] == "NULL" ? null : item["currentAddress"]; - profile.currentProvinceId = - item["currentProvinceId"] == "NULL" ? null : item["currentProvinceId"]; - profile.currentDistrictId = - item["currentDistrictId"] == "NULL" ? null : item["currentDistrictId"]; - profile.currentSubDistrictId = - item["currentSubDistrictId"] == "NULL" ? null : item["currentSubDistrictId"]; - profile.currentZipCode = item["currentZipCode"] == "NULL" ? null : item["currentZipCode"]; - profile.avatar = item["avatar"] == "NULL" ? null : item["avatar"]; - profile.avatarName = item["avatarName"] == "NULL" ? null : item["avatarName"]; - // profile.dateRetireLaw = - // item["dateRetireLaw"] == "NULL" ? null : new Date(item["dateRetireLaw"]); - profile.leaveReason = item["leaveReason"] == "NULL" ? null : item["leaveReason"]; - profile.dutyTimeId = item["dutyTimeId"] == "NULL" ? null : item["dutyTimeId"]; - // profile.dutyTimeEffectiveDate = - // item["dutyTimeEffectiveDate"] == "NULL" ? null : new Date(item["dutyTimeEffectiveDate"]); - - profiles.push(profile); - }), - ); - await this.profileRepo.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); - } - - @Post("uploadSQLSalary") + /** + * @summary เงินเดือน ข้าราชการ + */ + @Post("uploadProfileSalary-Officer") @UseInterceptors(FileInterceptor("file")) async UploadFileSQLSalary( @UploadedFile() file: Express.Multer.File, - // @Request() request: { user: Record }, + @Request() request: { user: Record }, ) { const workbook = xlsx.read(file.buffer, { type: "buffer" }); - let profiles: any = []; - let allData: any[] = []; - for (const sheetName of workbook.SheetNames) { - const sheet = workbook.Sheets[sheetName]; - const getProFile = xlsx.utils.sheet_to_json(sheet); - - await Promise.all( - getProFile.map(async (item: any) => { - const profile = new ProfileSalary(); - const existingProfile = await this.salaryRepository.findOne({ - where: { id: item["id"] }, - }); - if (existingProfile) { - return; - } - 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.date = item["date"] == "NULL" ? null : new Date(item["date"]); - profile.amount = item["amount"] == "NULL" ? null : item["amount"]; - profile.positionSalaryAmount = - item["positionSalaryAmount"] == "NULL" ? null : item["positionSalaryAmount"]; - profile.mouthSalaryAmount = - item["mouthSalaryAmount"] == "NULL" ? null : item["mouthSalaryAmount"]; - profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; - profile.refCommandNo = item["refCommandNo"] == "NULL" ? null : item["refCommandNo"]; - profile.posNo = item["posNo"] == "NULL" ? null : item["posNo"]; - profile.position = item["position"] == "NULL" ? null : item["position"]; - profile.positionLine = item["positionLine"] == "NULL" ? null : item["positionLine"]; - profile.positionPathSide = - item["positionPathSide"] == "NULL" ? null : item["positionPathSide"]; - profile.positionExecutive = - item["positionExecutive"] == "NULL" ? null : item["positionExecutive"]; - profile.positionType = item["positionType"] == "NULL" ? null : item["positionType"]; - profile.positionLevel = item["positionLevel"] == "NULL" ? null : item["positionLevel"]; - profile.templateDoc = item["templateDoc"] == "NULL" ? null : item["templateDoc"]; - profile.order = item["order"] == "NULL" ? null : item["order"]; - profile.profileEmployeeId = - item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; - profiles.push(profile); - }), - ); - - allData = allData.concat(getProFile); - } - await this.salaryRepository.save(profiles); - return new HttpSuccess(allData); - } - - @Post("uploadposSQL") - @UseInterceptors(FileInterceptor("file")) - async UploadPOSFileSQL(@UploadedFile() file: Express.Multer.File) { - const workbook = xlsx.read(file.buffer, { type: "buffer" }); - const sheetName = workbook.SheetNames[0]; + const sheetName = workbook.SheetNames[0] const sheet = workbook.Sheets[sheetName]; - const getProFile = xlsx.utils.sheet_to_json(sheet); - let profiles: any = []; + const getExcel = xlsx.utils.sheet_to_json(sheet); + let profileSalarys: any = []; + let null_: any=null await Promise.all( - getProFile.map(async (item: any) => { - // Find profile by ID - let profile = await this.profileRepo.findOne({ - where: { citizenId: item["ID"] }, + 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 (!profile) { - return; // Skip processing this item + if (!existingProfile) { + return; } - - if (item["MP_CEE_TYPE"] === "NULL") { - profile.posTypeId = null; - } else { - // Find posType by posTypeName - const posType = await this.posTypeRepo.findOne({ - where: { posTypeName: item["MP_CEE_TYPE"] }, - }); - if (!posType) { - return; // Skip processing this item - } - profile.posTypeId = posType.id; - } - // Check if posLevelName is "NULL" - if (item["MP_CEE_POSITION"] === "NULL") { - profile.posLevelId = null; - } else { - // Find posLevel by posLevelName - const posLevel = await this.posLevelRepo.findOne({ - where: { posLevelName: item["MP_CEE_POSITION"] }, - }); - if (!posLevel) { - console.error( - `posLevel with name ${item["MP_CEE_POSITION"]} not found for profile ID ${profile.id}`, - ); - return; // Skip processing this item - } - profile.posLevelId = posLevel.id; - } - - profiles.push(profile); + + 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.profileRepo.save(profiles); - return new HttpSuccess(getProFile); + await this.salaryRepository.save(profileSalarys); + return new HttpSuccess(profileSalarys); } + + /** + * @summary เงินเดือน ลูกจ้างประจำ + */ + @Post("uploadProfileSalary-Employee") + @UseInterceptors(FileInterceptor("file")) + async UploadFileSQLSalaryEmp( + @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 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(profileSalarys); + } + + /** + * @summary ครอบครัว ข้าราชการ + */ + @Post("uploadProfileFamily-Officer") + @UseInterceptors(FileInterceptor("file")) + async UploadFileSQLFamily( + @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 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(result); + } + + /** + * @summary ครอบครัว ลูกจ้างประจำ + */ + @Post("uploadProfileFamily-Employee") + @UseInterceptors(FileInterceptor("file")) + async UploadFileSQLFamilyEmp( + @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 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(result); + } + + // /** + // * @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); + // } } diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index b08092bb..e3469e11 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -1,6 +1,46 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; +import moment from 'moment'; + class Extension { + public static ConvertToDateTime(value: any) { + + if (value != "" && value != null ) { + if(isNaN(value)){ + let date = moment(value, 'DD/MM/YYYY').toDate(); + let year = date.getFullYear(); + if (year < 1800) { + return null; + } else if (year > 2500) { + date.setFullYear(year - 543); + } + return date; + } + // else { + // return moment.unix(value).format('DD/MM/YYYY'); + // } + } + return null; + } + + public static CheckRelationship(value: any) { + if(value!= "" && value != null) { + switch(value) { + case 1: + return "โสด"; + case 2: + return "สมรส"; + case 3: + return "หย่า"; + case 4: + return "หม้าย"; + default: + return ""; + } + } + return ""; + } + public static ToThaiMonth(value: number) { switch (value) { case 1: diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 4b58fdd4..3961271b 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -45,7 +45,7 @@ export function calculateRetireDate(birthDate: Date) { var year = d.getFullYear(); var month = d.getMonth(); var day = d.getDate(); - var c = new Date(year + 60, month, day); + var c = new Date(year + 60, month, day-1); return c; } export function calculateRetireLaw(birthDate: Date) {