Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

# Conflicts:
#	src/controllers/ImportDataController.ts
This commit is contained in:
Kittapath 2024-07-26 14:59:34 +07:00
commit 7c7ae7db41
8 changed files with 669 additions and 320 deletions

View file

@ -20,16 +20,16 @@ import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import { UseInterceptors } from "@nestjs/common"; import { UseInterceptors } from "@nestjs/common";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { FileInterceptor } from "@nestjs/platform-express"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import * as xlsx from "xlsx";
import { ProfileEducation } from "../entities/ProfileEducation";
import { ProfileSalary } from "../entities/ProfileSalary"; import { ProfileSalary } from "../entities/ProfileSalary";
import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyMother } from "../entities/ProfileFamilyMother"; import { ProfileFamilyMother } from "../entities/ProfileFamilyMother";
import { ProfileFamilyFather } from "../entities/ProfileFamilyFather"; import { ProfileFamilyFather } from "../entities/ProfileFamilyFather";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEducation } from "../entities/ProfileEducation";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType"; import { PosType } from "../entities/PosType";
import { FileInterceptor } from "@nestjs/platform-express";
import * as xlsx from "xlsx";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import { import {
calculateAge, calculateAge,
@ -48,6 +48,14 @@ import { HR_PERSONAL_OFFICER_FAMILY } from "../entities/HR_PERSONAL_OFFICER_FAMI
const BATCH_SIZE = 1000; const BATCH_SIZE = 1000;
// import { EducationMis } from "../entities/EducationMis"; // import { EducationMis } from "../entities/EducationMis";
import moment from "moment";
import { EducationMis } from "../entities/EducationMis";
import { ProvinceImport } from "../entities/ProvinceImport";
import { AmphurImport } from "../entities/AmphurImport";
import { SubDistrictImport } from "../entities/SubDistrictImport";
import { Province } from "../entities/Province";
import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict";
@Route("api/v1/org/upload") @Route("api/v1/org/upload")
@Tags("UPLOAD") @Tags("UPLOAD")
@ -65,6 +73,13 @@ export class ImportDataController extends Controller {
private HR_POSITION_OFFICERRepo = AppDataSource.getRepository(HR_POSITION_OFFICER); private HR_POSITION_OFFICERRepo = AppDataSource.getRepository(HR_POSITION_OFFICER);
private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_OFFICER_FAMILY); private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_OFFICER_FAMILY);
private educationMisRepo = AppDataSource.getRepository(EducationMis);
private provincsRepo = AppDataSource.getRepository(ProvinceImport);
private amphurRepo = AppDataSource.getRepository(AmphurImport);
private subDistrictRepo = AppDataSource.getRepository(SubDistrictImport);
private provinceIdRepo = AppDataSource.getRepository(Province);
private districtIdRepo = AppDataSource.getRepository(District);
private subDistrictIdRepo = AppDataSource.getRepository(SubDistrict);
/** /**
* @summary * @summary
*/ */
@ -195,6 +210,7 @@ export class ImportDataController extends Controller {
} }
let dateRetire = Extension.ConvertToDateTime(item["MP_FORCE_DATE"]); let dateRetire = Extension.ConvertToDateTime(item["MP_FORCE_DATE"]);
profileEmp.citizenId = item["ID"] == "" ? "" : item["ID"]; profileEmp.citizenId = item["ID"] == "" ? "" : item["ID"];
profileEmp.employeeClass = profileEmp.employeeClass =
item["FLAG_PERSON_TYPE"] == "6" ? "PERM" : item["FLAG_PERSON_TYPE"] == "7" ? "TEMP" : ""; item["FLAG_PERSON_TYPE"] == "6" ? "PERM" : item["FLAG_PERSON_TYPE"] == "7" ? "TEMP" : "";
@ -644,322 +660,515 @@ export class ImportDataController extends Controller {
return new HttpSuccess(); return new HttpSuccess();
} }
// /** /**
// * @summary Import Education Code * @summary Import Education
// */ */
// @Post("uploadEducation-Code") @Post("ImportEducation")
// @UseInterceptors(FileInterceptor("file")) @UseInterceptors(FileInterceptor("file"))
// async UploadFileSQLEducationCode( async UploadFileSQLEducationCode(
// @UploadedFile() file: Express.Multer.File, @UploadedFile() file: Express.Multer.File,
// @Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
// ) { ) {
// const workbook = xlsx.read(file.buffer, { type: "buffer" }); const workbook = xlsx.read(file.buffer, { type: "buffer" });
// const sheetName = workbook.SheetNames[0] const sheetName = workbook.SheetNames[0];
// const sheet = workbook.Sheets[sheetName]; const sheet = workbook.Sheets[sheetName];
// const getExcel = xlsx.utils.sheet_to_json(sheet); const getExcel = xlsx.utils.sheet_to_json(sheet);
// let educationMis_: any = []; let educationMis_: any = [];
// await Promise.all( await Promise.all(
// getExcel.map(async (item: any) => { getExcel.map(async (item: any) => {
// const educationMis = new EducationMis(); const educationMis = new EducationMis();
// educationMis.EDUCATION_CODE = item.EDUCATION_CODE; educationMis.EDUCATION_CODE = item.EDUCATION_CODE;
// educationMis.EDUCATION_CODE = item.EDUCATION_CODE; educationMis.EDUCATION_NAME = item.EDUCATION_NAME;
// educationMis_.push(educationMis); educationMis.EDUCATION_ABB_NAME = item.EDUCATION_ABB_NAME;
educationMis.createdUserId = request.user.sub;
educationMis.createdFullName = request.user.name;
educationMis.lastUpdateUserId = request.user.sub;
educationMis.lastUpdateFullName = request.user.name;
educationMis_.push(educationMis);
}),
);
await this.educationMisRepo.save(educationMis_);
return new HttpSuccess(educationMis_);
}
// }), /**
// ); * @summary
// await this.educationMisRepo.save(educationMis_); */
// return new HttpSuccess(educationMis_); @Post("uploadProfileEducation-Officer")
// } @UseInterceptors(FileInterceptor("file"))
async UploadFileSQLEducation(
@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 getEducations = xlsx.utils.sheet_to_json(sheet);
let educations: any = [];
let null_: any = null;
await Promise.all(
getEducations.map(async (item: any) => {
const education = new ProfileEducation();
const existingProfile = await this.profileRepo.findOne({
where: { citizenId: item.ID },
});
if (!existingProfile) {
return;
}
const educationCode = await this.educationMisRepo.findOne({
where: { EDUCATION_CODE: item.EDUCATION_CODE },
});
// /** let startDate = item.START_EDUCATION_YEAR
// * API upload EDU ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR)
// * : null_;
// * @summary DEV_0 - upload EDU # startDate = startDate ? new Date(startDate, 0, 1) : null_;
// *
// */
// @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( let endDate = item.EDUCATION_YEAR
// getEducations.map(async (item: any) => { ? Extension.ConvertToDateTime(item.EDUCATION_YEAR)
// if (item["id"] === undefined) { : null_;
// return; endDate = endDate ? new Date(endDate, 0, 1) : null_;
// }
// const education = new ProfileEducation();
// education.id = item["id"]; education.profileId = existingProfile.id;
// education.createdAt = item["createdAt"]; education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
// education.createdUserId = item["createdUserId"]; education.institute = item.INSTITUE;
// education.lastUpdatedAt = item["lastUpdatedAt"]; education.startDate = startDate;
// education.lastUpdateUserId = item["lastUpdateUserId"]; education.endDate = endDate;
// education.createdFullName = item["createdFullName"]; education.createdUserId = request.user.sub;
// education.lastUpdateFullName = item["lastUpdateFullName"]; education.createdFullName = request.user.name;
// education.profileId = item["profileId"]; education.lastUpdateUserId = request.user.sub;
// education.country = item["country"]; education.lastUpdateFullName = request.user.name;
// education.degree = item["degree"]; educations.push(education);
// education.duration = item["duration"]; }),
// education.durationYear = item["durationYear"]; );
// education.field = item["field"]; await this.educationRepository.save(educations);
// education.finishDate = item["finishDate"]; return new HttpSuccess();
// 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); /**
// }), * @summary
// ); */
// } @Post("uploadProfileEducation-Employee")
@UseInterceptors(FileInterceptor("file"))
async UploadFileSQLEducationEmp(
@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 getEducations = xlsx.utils.sheet_to_json(sheet);
let educations: any = [];
let null_: any = null;
await Promise.all(
getEducations.map(async (item: any) => {
const education = new ProfileEducation();
const existingProfile = await this.profileEmpRepo.findOne({
where: { citizenId: item.ID },
});
if (!existingProfile) {
return;
}
const educationCode = await this.educationMisRepo.findOne({
where: { EDUCATION_CODE: item.EDUCATION_CODE },
});
// @Post("uploadSQLEdu") let startDate = item.START_EDUCATION_YEAR
// @UseInterceptors(FileInterceptor("file")) ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR)
// async UploadFileSQLEdu( : null_;
// @UploadedFile() file: Express.Multer.File, startDate = startDate ? new Date(startDate, 0, 1) : null_;
// @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(); let endDate = item.EDUCATION_YEAR
// // Check if the profile already exists ? Extension.ConvertToDateTime(item.EDUCATION_YEAR)
// const existingProfile = await this.educationRepository.findOne({ : null_;
// where: { id: item["id"] }, endDate = endDate ? new Date(endDate, 0, 1) : null_;
// });
// // 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"]; education.profileEmployeeId = existingProfile.id;
// // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
// profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; education.institute = item.INSTITUE;
// // profile.lastUpdatedAt = education.startDate = startDate;
// // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); education.endDate = endDate;
// profile.lastUpdateUserId = education.createdUserId = request.user.sub;
// item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; education.createdFullName = request.user.name;
// profile.createdFullName = education.lastUpdateUserId = request.user.sub;
// item["createdFullName"] == "NULL" ? null : item["createdFullName"]; education.lastUpdateFullName = request.user.name;
// profile.lastUpdateFullName = educations.push(education);
// item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; }),
// profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; );
// profile.country = item["country"] == "NULL" ? null : item["country"]; await this.educationRepository.save(educations);
// profile.degree = item["degree"] == "NULL" ? null : item["degree"]; return new HttpSuccess();
// 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); /**
// }), * @summary Import Province
// ); */
// await this.educationRepository.save(profiles); @Post("ImportProvince")
// return new HttpSuccess(getProFile); @UseInterceptors(FileInterceptor("file"))
// } async ImportProvince(
@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 provinces_: any = [];
// @Post("uploadSQLFamilly-Father") await Promise.all(
// @UseInterceptors(FileInterceptor("file")) getExcel.map(async (item: any) => {
// async UploadFileSQLFamilly( const prov = new ProvinceImport();
// @UploadedFile() file: Express.Multer.File, prov.PROVINCE_CODE = item.PROVINCE_CODE;
// // @Request() request: { user: Record<string, any> }, prov.PROVINCE_NAME = item.PROVINCE_NAME;
// ) { prov.createdUserId = request.user.sub;
// const workbook = xlsx.read(file.buffer, { type: "buffer" }); prov.createdFullName = request.user.name;
// const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet prov.lastUpdateUserId = request.user.sub;
// const sheet = workbook.Sheets[sheetName]; prov.lastUpdateFullName = request.user.name;
// const getProFile = xlsx.utils.sheet_to_json(sheet); provinces_.push(prov);
// let profiles: any = []; }),
// await Promise.all( );
// getProFile.map(async (item: any) => { await this.provincsRepo.save(provinces_);
// // Create a new Profile entity and assign fields from the parsed data return new HttpSuccess(provinces_);
}
// const profile = new ProfileFamilyFather(); /**
// // Check if the profile already exists * @summary Import Amphur
// const existingProfile = await this.profileFamilyFatherRepository.findOne({ */
// where: { id: item["id"] }, @Post("ImportAmphur")
// }); @UseInterceptors(FileInterceptor("file"))
// // If profile exists, skip saving async ImportAmphur(
// if (existingProfile) { @UploadedFile() file: Express.Multer.File,
// return; @Request() request: { user: Record<string, any> },
// } ) {
// // Assign fields from the item to the profile entit 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 amphur_: any = [];
// profile.id = item["id"] == "NULL" ? null : item["id"]; await Promise.all(
// // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); getExcel.map(async (item: any) => {
// profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; const amh = new AmphurImport();
// // profile.lastUpdatedAt = amh.PROVINCE_CODE = item.PROVINCE_CODE;
// // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); amh.AMPHUR_CODE = item.AMPHUR_CODE;
// profile.lastUpdateUserId = amh.AMPHUR_NAME = item.AMPHUR_NAME;
// item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; amh.createdUserId = request.user.sub;
// profile.createdFullName = amh.createdFullName = request.user.name;
// item["createdFullName"] == "NULL" ? null : item["createdFullName"]; amh.lastUpdateUserId = request.user.sub;
// profile.lastUpdateFullName = amh.lastUpdateFullName = request.user.name;
// item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; amphur_.push(amh);
// profile.fatherPrefix = item["fatherPrefix"] == "NULL" ? null : item["fatherPrefix"]; }),
// profile.fatherFirstName = );
// item["fatherFirstName"] == "NULL" ? null : item["fatherFirstName"]; await this.amphurRepo.save(amphur_);
// profile.fatherLastName = item["fatherLastName"] == "NULL" ? null : item["fatherLastName"]; return new HttpSuccess(amphur_);
// 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")) * @summary Import SubDistrict
// async UploadFileSQLFamillyMother( */
// @UploadedFile() file: Express.Multer.File, @Post("ImportSubDistrict")
// @Request() request: { user: Record<string, any> }, @UseInterceptors(FileInterceptor("file"))
// ) { async ImportSubDistrict(
// const workbook = xlsx.read(file.buffer, { type: "buffer" }); @UploadedFile() file: Express.Multer.File,
// const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet @Request() request: { user: Record<string, any> },
// const sheet = workbook.Sheets[sheetName]; ) {
// const getProFile = xlsx.utils.sheet_to_json(sheet); const workbook = xlsx.read(file.buffer, { type: "buffer" });
// let profiles: any = []; const sheetName = workbook.SheetNames[0];
// await Promise.all( const sheet = workbook.Sheets[sheetName];
// getProFile.map(async (item: any) => { const getExcel = xlsx.utils.sheet_to_json(sheet);
// // Create a new Profile entity and assign fields from the parsed data let subDistrict_: any = [];
// const profile = new ProfileFamilyMother(); await Promise.all(
// // Check if the profile already exists getExcel.map(async (item: any) => {
// const existingProfile = await this.profileFamilyMotherRepository.findOne({ const subD = new SubDistrictImport();
// where: { id: item["id"] }, subD.PROVINCE_CODE = item.PROVINCE_CODE;
// }); subD.AMPHUR_CODE = item.AMPHUR_CODE;
// // If profile exists, skip saving subD.DISTRICT_CODE = item.DISTRICT_CODE;
// if (existingProfile) { subD.DISTRICT_NAME = item.DISTRICT_NAME;
// return; subD.createdUserId = request.user.sub;
// } subD.createdFullName = request.user.name;
// // Assign fields from the item to the profile entit subD.lastUpdateUserId = request.user.sub;
subD.lastUpdateFullName = request.user.name;
subDistrict_.push(subD);
}),
);
await this.subDistrictRepo.save(subDistrict_);
return new HttpSuccess(subDistrict_);
}
// profile.id = item["id"] == "NULL" ? null : item["id"]; /**
// // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); * @summary -
// profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; */
// // profile.lastUpdatedAt = @Post("uploadProfileAddress-Officer")
// // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); @UseInterceptors(FileInterceptor("file"))
// profile.lastUpdateUserId = async UploadFileSQLAddress(
// item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; @UploadedFile() file: Express.Multer.File,
// profile.createdFullName = @Request() request: { user: Record<string, any> },
// item["createdFullName"] == "NULL" ? null : item["createdFullName"]; ) {
// profile.lastUpdateFullName = const workbook = xlsx.read(file.buffer, { type: "buffer" });
// item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; const sheetName = workbook.SheetNames[0];
// profile.motherPrefix = item["motherPrefix"] == "NULL" ? null : item["motherPrefix"]; const sheet = workbook.Sheets[sheetName];
// profile.motherFirstName = const getAddress = xlsx.utils.sheet_to_json(sheet);
// item["motherFirstName"] == "NULL" ? null : item["motherFirstName"]; let null_: any = null;
// profile.motherLastName = item["motherLastName"] == "NULL" ? null : item["motherLastName"]; await Promise.all(
// profile.motherCareer = item["motherCareer"] == "NULL" ? null : item["motherCareer"]; getAddress.map(async (item: any) => {
// profile.motherCitizenId = let provinceRegis_: any = null;
// item["motherCitizenId"] == "NULL" ? null : item["motherCitizenId"]; let districtRegis_: any = null;
// profile.motherLive = item["motherLive"] == "NULL" ? null : item["motherLive"]; let subDistrictRegis_: any = null;
// profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; let provinceCurr_: any = null;
// profile.profileEmployeeId = let districtCurr_: any = null;
// item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; let subDistrictCurr_: any = null;
// profiles.push(profile); const existingProfile = await this.profileRepo.findOne({
// }), where: { citizenId: item.ID },
// ); });
// await this.profileFamilyMotherRepository.save(profiles); if (!existingProfile) {
// return new HttpSuccess(getProFile); return;
// } } else {
//registration address
if (item["PROVINCE_CODE"]) {
provinceRegis_ = await this.provincsRepo.findOne({
where: { PROVINCE_CODE: item["PROVINCE_CODE"] },
});
if (provinceRegis_) {
let provinceId = await this.provinceIdRepo.findOne({
where: {
name: provinceRegis_.PROVINCE_NAME,
},
});
existingProfile.registrationProvinceId = provinceId ? provinceId.id : null_;
}
}
if (item["AMPHUR_CODE"]) {
districtRegis_ = await this.amphurRepo.findOne({
where: {
AMPHUR_CODE: item["AMPHUR_CODE"],
PROVINCE_CODE: provinceRegis_.PROVINCE_CODE,
},
});
if (districtRegis_) {
let districtId = await this.districtIdRepo.findOne({
where: {
name: districtRegis_.AMPHUR_NAME,
},
});
existingProfile.registrationDistrictId = districtId ? districtId.id : null_;
}
}
if (item["DISTRICT_CODE"]) {
subDistrictRegis_ = await this.subDistrictRepo.findOne({
where: {
DISTRICT_CODE: item["DISTRICT_CODE"],
AMPHUR_CODE: districtRegis_.AMPHUR_CODE,
PROVINCE_CODE: provinceRegis_.PROVINCE_CODE,
},
});
if (subDistrictRegis_) {
let subDistrictId = await this.subDistrictIdRepo.findOne({
where: {
name: subDistrictRegis_.DISTRICT_NAME,
},
});
existingProfile.registrationSubDistrictId = subDistrictId ? subDistrictId.id : null_;
}
}
//current address
if (item["CONTACT_PROVINCE_CODE"]) {
provinceCurr_ = await this.provincsRepo.findOne({
where: { PROVINCE_CODE: item["CONTACT_PROVINCE_CODE"] },
});
if (provinceCurr_) {
let provinceId = await this.provinceIdRepo.findOne({
where: {
name: provinceCurr_.PROVINCE_NAME,
},
});
existingProfile.currentProvinceId = provinceId ? provinceId.id : null_;
}
}
if (item["CONTACT_AMPHUR_CODE"]) {
districtCurr_ = await this.amphurRepo.findOne({
where: {
AMPHUR_CODE: item["CONTACT_AMPHUR_CODE"],
PROVINCE_CODE: provinceCurr_.PROVINCE_CODE,
},
});
if (districtCurr_) {
let districtId = await this.districtIdRepo.findOne({
where: {
name: districtCurr_.AMPHUR_NAME,
},
});
existingProfile.currentDistrictId = districtId ? districtId.id : null_;
}
}
if (item["CONTACT_DISTRICT_CODE"]) {
subDistrictCurr_ = await this.subDistrictRepo.findOne({
where: {
DISTRICT_CODE: item["CONTACT_DISTRICT_CODE"],
AMPHUR_CODE: districtCurr_.AMPHUR_CODE,
PROVINCE_CODE: provinceCurr_.PROVINCE_CODE,
},
});
if (subDistrictCurr_) {
let subDistrictId = await this.subDistrictIdRepo.findOne({
where: {
name: subDistrictCurr_.DISTRICT_NAME,
},
});
existingProfile.currentSubDistrictId = subDistrictId ? subDistrictId.id : null_;
}
}
existingProfile.registrationAddress = item.H_NUMBER;
existingProfile.registrationZipCode = item.ZIPCODE;
existingProfile.currentAddress = item.CONTACT_H_NUMBER;
existingProfile.currentZipCode = item.CONTACT_ZIPCODE;
existingProfile.createdUserId = request.user.sub;
existingProfile.createdFullName = request.user.name;
existingProfile.lastUpdateUserId = request.user.sub;
existingProfile.lastUpdateFullName = request.user.name;
await this.profileRepo.save(existingProfile);
}
}),
);
return new HttpSuccess();
}
// @Post("uploadSQLFamilly-Couple") /**
// @UseInterceptors(FileInterceptor("file")) * @summary -
// async UploadFileSQLFamillyCouple( */
// @UploadedFile() file: Express.Multer.File, @Post("uploadProfileAddress-Employee")
// // @Request() request: { user: Record<string, any> }, @UseInterceptors(FileInterceptor("file"))
// ) { async UploadFileSQLAddressEmp(
// const workbook = xlsx.read(file.buffer, { type: "buffer" }); @UploadedFile() file: Express.Multer.File,
// const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet @Request() request: { user: Record<string, any> },
// const sheet = workbook.Sheets[sheetName]; ) {
// const getProFile = xlsx.utils.sheet_to_json(sheet); const workbook = xlsx.read(file.buffer, { type: "buffer" });
// let profiles: any = []; const sheetName = workbook.SheetNames[0];
// await Promise.all( const sheet = workbook.Sheets[sheetName];
// getProFile.map(async (item: any) => { const getAddress = xlsx.utils.sheet_to_json(sheet);
// // Create a new Profile entity and assign fields from the parsed data let null_: any = null;
await Promise.all(
// const profile = new ProfileFamilyCouple(); getAddress.map(async (item: any) => {
// // Check if the profile already exists let provinceRegis_: any = null;
// const existingProfile = await this.profileFamilyCoupleRepository.findOne({ let districtRegis_: any = null;
// where: { id: item["id"] }, let subDistrictRegis_: any = null;
// }); let provinceCurr_: any = null;
// // If profile exists, skip saving let districtCurr_: any = null;
// if (existingProfile) { let subDistrictCurr_: any = null;
// return; const existingProfileEmp = await this.profileEmpRepo.findOne({
// } where: { citizenId: item.ID },
// // Assign fields from the item to the profile entit });
if (!existingProfileEmp) {
// profile.id = item["id"] == "NULL" ? null : item["id"]; return;
// // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); } else {
// profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; //registration address
// // profile.lastUpdatedAt = if (item["PROVINCE_CODE"]) {
// // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); provinceRegis_ = await this.provincsRepo.findOne({
// profile.lastUpdateUserId = where: { PROVINCE_CODE: item["PROVINCE_CODE"] },
// item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; });
// profile.createdFullName = if (provinceRegis_) {
// item["createdFullName"] == "NULL" ? null : item["createdFullName"]; let provinceId = await this.provinceIdRepo.findOne({
// profile.lastUpdateFullName = where: {
// item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; name: provinceRegis_.PROVINCE_NAME,
// profile.couple = item["couple"] == "NULL" ? null : item["couple"]; },
// profile.couplePrefix = item["couplePrefix"] == "NULL" ? null : item["couplePrefix"]; });
// profile.coupleFirstName = existingProfileEmp.registrationProvinceId = provinceId ? provinceId.id : null_;
// item["coupleFirstName"] == "NULL" ? null : item["coupleFirstName"]; }
// profile.coupleLastName = item["coupleLastName"] == "NULL" ? null : item["coupleLastName"]; }
// profile.coupleLastNameOld = if (item["AMPHUR_CODE"]) {
// item["coupleLastNameOld"] == "NULL" ? null : item["coupleLastNameOld"]; districtRegis_ = await this.amphurRepo.findOne({
// profile.coupleCareer = item["coupleCareer"] == "NULL" ? null : item["coupleCareer"]; where: {
// profile.coupleCitizenId = AMPHUR_CODE: item["AMPHUR_CODE"],
// item["coupleCitizenId"] == "NULL" ? null : item["coupleCitizenId"]; PROVINCE_CODE: provinceRegis_.PROVINCE_CODE,
// profile.coupleLive = item["coupleLive"] == "NULL" ? null : item["coupleLive"]; },
// profile.relationship = item["relationship"] == "NULL" ? null : item["relationship"]; });
// profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; if (districtRegis_) {
// profile.profileEmployeeId = let districtId = await this.districtIdRepo.findOne({
// item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; where: {
// profiles.push(profile); name: districtRegis_.AMPHUR_NAME,
// }), },
// ); });
// await this.profileFamilyCoupleRepository.save(profiles); existingProfileEmp.registrationDistrictId = districtId ? districtId.id : null_;
// return new HttpSuccess(getProFile); }
// } }
if (item["DISTRICT_CODE"]) {
subDistrictRegis_ = await this.subDistrictRepo.findOne({
where: {
DISTRICT_CODE: item["DISTRICT_CODE"],
AMPHUR_CODE: districtRegis_.AMPHUR_CODE,
PROVINCE_CODE: provinceRegis_.PROVINCE_CODE,
},
});
if (subDistrictRegis_) {
let subDistrictId = await this.subDistrictIdRepo.findOne({
where: {
name: subDistrictRegis_.DISTRICT_NAME,
},
});
existingProfileEmp.registrationSubDistrictId = subDistrictId
? subDistrictId.id
: null_;
}
}
//current address
if (item["CONTACT_PROVINCE_CODE"]) {
provinceCurr_ = await this.provincsRepo.findOne({
where: { PROVINCE_CODE: item["CONTACT_PROVINCE_CODE"] },
});
if (provinceCurr_) {
let provinceId = await this.provinceIdRepo.findOne({
where: {
name: provinceCurr_.PROVINCE_NAME,
},
});
existingProfileEmp.currentProvinceId = provinceId ? provinceId.id : null_;
}
}
if (item["CONTACT_AMPHUR_CODE"]) {
districtCurr_ = await this.amphurRepo.findOne({
where: {
AMPHUR_CODE: item["CONTACT_AMPHUR_CODE"],
PROVINCE_CODE: provinceCurr_.PROVINCE_CODE,
},
});
if (districtCurr_) {
let districtId = await this.districtIdRepo.findOne({
where: {
name: districtCurr_.AMPHUR_NAME,
},
});
existingProfileEmp.currentDistrictId = districtId ? districtId.id : null_;
}
}
if (item["CONTACT_DISTRICT_CODE"]) {
subDistrictCurr_ = await this.subDistrictRepo.findOne({
where: {
DISTRICT_CODE: item["CONTACT_DISTRICT_CODE"],
AMPHUR_CODE: districtCurr_.AMPHUR_CODE,
PROVINCE_CODE: provinceCurr_.PROVINCE_CODE,
},
});
if (subDistrictCurr_) {
let subDistrictId = await this.subDistrictIdRepo.findOne({
where: {
name: subDistrictCurr_.DISTRICT_NAME,
},
});
existingProfileEmp.currentSubDistrictId = subDistrictId ? subDistrictId.id : null_;
}
}
existingProfileEmp.registrationAddress = item.H_NUMBER;
existingProfileEmp.registrationZipCode = item.ZIPCODE;
existingProfileEmp.currentAddress = item.CONTACT_H_NUMBER;
existingProfileEmp.currentZipCode = item.CONTACT_ZIPCODE;
existingProfileEmp.createdUserId = request.user.sub;
existingProfileEmp.createdFullName = request.user.name;
existingProfileEmp.lastUpdateUserId = request.user.sub;
existingProfileEmp.lastUpdateFullName = request.user.name;
await this.profileEmpRepo.save(existingProfileEmp);
}
}),
);
return new HttpSuccess();
}
} }

View file

@ -0,0 +1,26 @@
import { Entity, Column} from "typeorm";
import { EntityBase } from "./base/Base";
@Entity("amphurImport")
export class AmphurImport extends EntityBase{
@Column({
nullable: true,
length: 255,
default: null,
})
PROVINCE_CODE: string;
@Column({
nullable: true,
length: 255,
default: null,
})
AMPHUR_CODE: string;
@Column({
nullable: true,
length: 255,
default: null,
})
AMPHUR_NAME: string;
}

View file

@ -0,0 +1,26 @@
import { Entity, Column} from "typeorm";
import { EntityBase } from "./base/Base";
@Entity("educationMis")
export class EducationMis extends EntityBase{
@Column({
nullable: true,
length: 255,
default: null,
})
EDUCATION_CODE: string;
@Column({
nullable: true,
length: 255,
default: null,
})
EDUCATION_NAME: string;
@Column({
nullable: true,
length: 255,
default: null,
})
EDUCATION_ABB_NAME: string;
}

View file

@ -0,0 +1,19 @@
import { Entity, Column} from "typeorm";
import { EntityBase } from "./base/Base";
@Entity("provinceImport")
export class ProvinceImport extends EntityBase{
@Column({
nullable: true,
length: 255,
default: null,
})
PROVINCE_CODE: string;
@Column({
nullable: true,
length: 255,
default: null,
})
PROVINCE_NAME: string;
}

View file

@ -0,0 +1,33 @@
import { Entity, Column} from "typeorm";
import { EntityBase } from "./base/Base";
@Entity("subDistrictImport")
export class SubDistrictImport extends EntityBase{
@Column({
nullable: true,
length: 255,
default: null,
})
PROVINCE_CODE: string;
@Column({
nullable: true,
length: 255,
default: null,
})
AMPHUR_CODE: string;
@Column({
nullable: true,
length: 255,
default: null,
})
DISTRICT_CODE: string;
@Column({
nullable: true,
length: 255,
default: null,
})
DISTRICT_NAME: string;
}

View file

@ -1,31 +1,35 @@
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import moment from 'moment'; import moment from "moment";
class Extension { class Extension {
public static ConvertToDateTime(value: any) { public static ConvertToDateTime(value: any) {
if (value != "" && value != null) {
if (value != "" && value != null ) { if (isNaN(value)) {
if(isNaN(value)){ let date = moment(value, "DD/MM/YYYY").toDate();
let date = moment(value, 'DD/MM/YYYY').toDate();
let year = date.getFullYear(); let year = date.getFullYear();
if (year < 1800) { if (year < 1800) {
return null; return null;
} else if (year > 2500) { } else if (year > 2500) {
date.setFullYear(year - 543); date.setFullYear(year - 543);
} }
return date; return date;
} else {
if (value.toString().length == 4) {
if (value < 1800) {
return null;
} else if (value > 2500) {
return new Date(value - 543, 0, 1);
}
}
} }
// else {
// return moment.unix(value).format('DD/MM/YYYY');
// }
} }
return null; return null;
} }
public static CheckRelationship(value: any) { public static CheckRelationship(value: any) {
if(value!= "" && value != null) { if (value != "" && value != null) {
switch(value) { switch (value) {
case 1: case 1:
return "โสด"; return "โสด";
case 2: case 2:

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableEducationMis1721902034164 implements MigrationInterface {
name = 'AddTableEducationMis1721902034164'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`educationMis\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`EDUCATION_CODE\` varchar(255) NULL, \`EDUCATION_NAME\` varchar(255) NULL, \`EDUCATION_ABB_NAME\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE \`educationMis\``);
}
}

View file

@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableAddressImport1721964204244 implements MigrationInterface {
name = 'AddTableAddressImport1721964204244'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`provinceImport\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`PROVINCE_CODE\` varchar(255) NULL, \`PROVINCE_NAME\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`subDistrictImport\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`PROVINCE_CODE\` varchar(255) NULL, \`AMPHUR_CODE\` varchar(255) NULL, \`DISTRICT_CODE\` varchar(255) NULL, \`DISTRICT_NAME\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`amphurImport\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`PROVINCE_CODE\` varchar(255) NULL, \`AMPHUR_CODE\` varchar(255) NULL, \`AMPHUR_NAME\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE \`amphurImport\``);
await queryRunner.query(`DROP TABLE \`subDistrictImport\``);
await queryRunner.query(`DROP TABLE \`provinceImport\``);
}
}