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;
// await this.educationMisRepo.save(educationMis_); educationMis.lastUpdateFullName = request.user.name;
// return new HttpSuccess(educationMis_); educationMis_.push(educationMis);
// } }),
);
// /** await this.educationMisRepo.save(educationMis_);
// * API upload EDU return new HttpSuccess(educationMis_);
// * }
// * @summary DEV_0 - upload EDU #
// * /**
// */ * @summary
// @Post("") */
// @UseInterceptors(FileInterceptor("file")) @Post("uploadProfileEducation-Officer")
// async UploadUserDevelopemtById(@UploadedFile() file: Express.Multer.File) { @UseInterceptors(FileInterceptor("file"))
// const workbook = xlsx.read(file.buffer, { type: "buffer" }); async UploadFileSQLEducation(
// const sheetName = workbook.SheetNames[1]; @UploadedFile() file: Express.Multer.File,
// const sheet = workbook.Sheets[sheetName]; @Request() request: { user: Record<string, any> },
// const getEducations = xlsx.utils.sheet_to_json(sheet); ) {
const workbook = xlsx.read(file.buffer, { type: "buffer" });
// await Promise.all( const sheetName = workbook.SheetNames[0];
// getEducations.map(async (item: any) => { const sheet = workbook.Sheets[sheetName];
// if (item["id"] === undefined) { const getEducations = xlsx.utils.sheet_to_json(sheet);
// return; let educations: any = [];
// } let null_: any = null;
// const education = new ProfileEducation(); await Promise.all(
getEducations.map(async (item: any) => {
// education.id = item["id"]; const education = new ProfileEducation();
// education.createdAt = item["createdAt"]; const existingProfile = await this.profileRepo.findOne({
// education.createdUserId = item["createdUserId"]; where: { citizenId: item.ID },
// education.lastUpdatedAt = item["lastUpdatedAt"]; });
// education.lastUpdateUserId = item["lastUpdateUserId"]; if (!existingProfile) {
// education.createdFullName = item["createdFullName"]; return;
// education.lastUpdateFullName = item["lastUpdateFullName"]; }
// education.profileId = item["profileId"]; const educationCode = await this.educationMisRepo.findOne({
// education.country = item["country"]; where: { EDUCATION_CODE: item.EDUCATION_CODE },
// education.degree = item["degree"]; });
// education.duration = item["duration"];
// education.durationYear = item["durationYear"]; let startDate = item.START_EDUCATION_YEAR
// education.field = item["field"]; ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR)
// education.finishDate = item["finishDate"]; : null_;
// education.fundName = item["fundName"]; startDate = startDate ? new Date(startDate, 0, 1) : null_;
// education.institute = item["institute"];
// education.other = item["other"]; let endDate = item.EDUCATION_YEAR
// education.startDate = item["startDate"]; ? Extension.ConvertToDateTime(item.EDUCATION_YEAR)
// education.endDate = item["endDate"]; : null_;
// education.educationLevel = item["educationLevel"]; endDate = endDate ? new Date(endDate, 0, 1) : null_;
// education.educationLevelId = item["educationLevelId"];
// education.positionPath = item["positionPath"]; education.profileId = existingProfile.id;
// education.positionPathId = item["positionPathId"]; education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
// education.isDate = item["isDate"]; education.institute = item.INSTITUE;
// education.isEducation = item["isEducation"]; education.startDate = startDate;
// education.note = item["note"]; education.endDate = endDate;
// education.profileEmployeeId = item["profileEmployeeId"]; education.createdUserId = request.user.sub;
education.createdFullName = request.user.name;
// await this.educationRepository.save(education); education.lastUpdateUserId = request.user.sub;
// }), education.lastUpdateFullName = request.user.name;
// ); educations.push(education);
// } }),
);
// @Post("uploadSQLEdu") await this.educationRepository.save(educations);
// @UseInterceptors(FileInterceptor("file")) return new HttpSuccess();
// async UploadFileSQLEdu( }
// @UploadedFile() file: Express.Multer.File,
// @Request() request: { user: Record<string, any> }, /**
// ) { * @summary
// const workbook = xlsx.read(file.buffer, { type: "buffer" }); */
// const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet @Post("uploadProfileEducation-Employee")
// const sheet = workbook.Sheets[sheetName]; @UseInterceptors(FileInterceptor("file"))
// const getProFile = xlsx.utils.sheet_to_json(sheet); async UploadFileSQLEducationEmp(
// let profiles: any = []; @UploadedFile() file: Express.Multer.File,
// await Promise.all( @Request() request: { user: Record<string, any> },
// getProFile.map(async (item: any) => { ) {
// // Create a new Profile entity and assign fields from the parsed data const workbook = xlsx.read(file.buffer, { type: "buffer" });
const sheetName = workbook.SheetNames[0];
// const profile = new ProfileEducation(); const sheet = workbook.Sheets[sheetName];
// // Check if the profile already exists const getEducations = xlsx.utils.sheet_to_json(sheet);
// const existingProfile = await this.educationRepository.findOne({ let educations: any = [];
// where: { id: item["id"] }, let null_: any = null;
// }); await Promise.all(
// // If profile exists, skip saving getEducations.map(async (item: any) => {
// if (existingProfile) { const education = new ProfileEducation();
// return; const existingProfile = await this.profileEmpRepo.findOne({
// } where: { citizenId: item.ID },
// // Assign fields from the item to the profile entit });
if (!existingProfile) {
// profile.id = item["id"] == "NULL" ? null : item["id"]; return;
// // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); }
// profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; const educationCode = await this.educationMisRepo.findOne({
// // profile.lastUpdatedAt = where: { EDUCATION_CODE: item.EDUCATION_CODE },
// // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); });
// profile.lastUpdateUserId =
// item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; let startDate = item.START_EDUCATION_YEAR
// profile.createdFullName = ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR)
// item["createdFullName"] == "NULL" ? null : item["createdFullName"]; : null_;
// profile.lastUpdateFullName = startDate = startDate ? new Date(startDate, 0, 1) : null_;
// item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"];
// profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; let endDate = item.EDUCATION_YEAR
// profile.country = item["country"] == "NULL" ? null : item["country"]; ? Extension.ConvertToDateTime(item.EDUCATION_YEAR)
// profile.degree = item["degree"] == "NULL" ? null : item["degree"]; : null_;
// profile.duration = item["duration"] == "NULL" ? null : item["duration"]; endDate = endDate ? new Date(endDate, 0, 1) : null_;
// profile.durationYear = item["durationYear"] == "NULL" ? null : item["durationYear"];
// profile.field = item["field"] == "NULL" ? null : item["field"]; education.profileEmployeeId = existingProfile.id;
// // profile.finishDate = item["finishDate"] == "NULL" ? null : new Date(item["finishDate"]); education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
// profile.fundName = item["fundName"] == "NULL" ? null : item["fundName"]; education.institute = item.INSTITUE;
// profile.gpa = item["gpa"] == "NULL" ? null : item["gpa"]; education.startDate = startDate;
// profile.institute = item["institute"] == "NULL" ? null : item["institute"]; education.endDate = endDate;
// profile.other = item["other"] == "NULL" ? null : item["other"]; education.createdUserId = request.user.sub;
// // profile.startDate = item["startDate"] == "NULL" ? null : new Date(item["startDate"]); education.createdFullName = request.user.name;
// // profile.endDate = item["endDate"] == "NULL" ? null : new Date(item["endDate"]); education.lastUpdateUserId = request.user.sub;
// profile.educationLevel = item["educationLevel"] == "NULL" ? null : item["educationLevel"]; education.lastUpdateFullName = request.user.name;
// profile.educationLevelId = educations.push(education);
// item["educationLevelId"] == "NULL" ? null : item["educationLevelId"]; }),
// profile.positionPath = item["positionPath"] == "NULL" ? null : item["positionPath"]; );
// profile.positionPathId = item["positionPathId"] == "NULL" ? null : item["positionPathId"]; await this.educationRepository.save(educations);
// profile.isDate = item["isDate"] == "NULL" ? null : item["isDate"]; return new HttpSuccess();
// profile.isEducation = item["isEducation"] == "NULL" ? null : item["isEducation"]; }
// profile.note = item["note"] == "NULL" ? null : item["note"];
// profile.profileEmployeeId = /**
// item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; * @summary Import Province
*/
// profiles.push(profile); @Post("ImportProvince")
// }), @UseInterceptors(FileInterceptor("file"))
// ); async ImportProvince(
// await this.educationRepository.save(profiles); @UploadedFile() file: Express.Multer.File,
// return new HttpSuccess(getProFile); @Request() request: { user: Record<string, any> },
// } ) {
const workbook = xlsx.read(file.buffer, { type: "buffer" });
// @Post("uploadSQLFamilly-Father") const sheetName = workbook.SheetNames[0];
// @UseInterceptors(FileInterceptor("file")) const sheet = workbook.Sheets[sheetName];
// async UploadFileSQLFamilly( const getExcel = xlsx.utils.sheet_to_json(sheet);
// @UploadedFile() file: Express.Multer.File, let provinces_: any = [];
// // @Request() request: { user: Record<string, any> },
// ) { await Promise.all(
// const workbook = xlsx.read(file.buffer, { type: "buffer" }); getExcel.map(async (item: any) => {
// const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet const prov = new ProvinceImport();
// const sheet = workbook.Sheets[sheetName]; prov.PROVINCE_CODE = item.PROVINCE_CODE;
// const getProFile = xlsx.utils.sheet_to_json(sheet); prov.PROVINCE_NAME = item.PROVINCE_NAME;
// let profiles: any = []; prov.createdUserId = request.user.sub;
// await Promise.all( prov.createdFullName = request.user.name;
// getProFile.map(async (item: any) => { prov.lastUpdateUserId = request.user.sub;
// // Create a new Profile entity and assign fields from the parsed data prov.lastUpdateFullName = request.user.name;
provinces_.push(prov);
// const profile = new ProfileFamilyFather(); }),
// // Check if the profile already exists );
// const existingProfile = await this.profileFamilyFatherRepository.findOne({ await this.provincsRepo.save(provinces_);
// where: { id: item["id"] }, return new HttpSuccess(provinces_);
// }); }
// // If profile exists, skip saving
// if (existingProfile) { /**
// return; * @summary Import Amphur
// } */
// // Assign fields from the item to the profile entit @Post("ImportAmphur")
@UseInterceptors(FileInterceptor("file"))
// profile.id = item["id"] == "NULL" ? null : item["id"]; async ImportAmphur(
// // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); @UploadedFile() file: Express.Multer.File,
// profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; @Request() request: { user: Record<string, any> },
// // profile.lastUpdatedAt = ) {
// // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); const workbook = xlsx.read(file.buffer, { type: "buffer" });
// profile.lastUpdateUserId = const sheetName = workbook.SheetNames[0];
// item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; const sheet = workbook.Sheets[sheetName];
// profile.createdFullName = const getExcel = xlsx.utils.sheet_to_json(sheet);
// item["createdFullName"] == "NULL" ? null : item["createdFullName"]; let amphur_: any = [];
// profile.lastUpdateFullName =
// item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; await Promise.all(
// profile.fatherPrefix = item["fatherPrefix"] == "NULL" ? null : item["fatherPrefix"]; getExcel.map(async (item: any) => {
// profile.fatherFirstName = const amh = new AmphurImport();
// item["fatherFirstName"] == "NULL" ? null : item["fatherFirstName"]; amh.PROVINCE_CODE = item.PROVINCE_CODE;
// profile.fatherLastName = item["fatherLastName"] == "NULL" ? null : item["fatherLastName"]; amh.AMPHUR_CODE = item.AMPHUR_CODE;
// profile.fatherCareer = item["fatherCareer"] == "NULL" ? null : item["fatherCareer"]; amh.AMPHUR_NAME = item.AMPHUR_NAME;
// profile.fatherCitizenId = amh.createdUserId = request.user.sub;
// item["fatherCitizenId"] == "NULL" ? null : item["fatherCitizenId"]; amh.createdFullName = request.user.name;
// profile.fatherLive = item["fatherLive"] == "NULL" ? null : item["fatherLive"]; amh.lastUpdateUserId = request.user.sub;
// profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; amh.lastUpdateFullName = request.user.name;
// profile.profileEmployeeId = amphur_.push(amh);
// item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; }),
// profiles.push(profile); );
// }), await this.amphurRepo.save(amphur_);
// ); return new HttpSuccess(amphur_);
// await this.profileFamilyFatherRepository.save(profiles); }
// return new HttpSuccess(getProFile);
// } /**
* @summary Import SubDistrict
// @Post("uploadSQLFamilly-Mother") */
// @UseInterceptors(FileInterceptor("file")) @Post("ImportSubDistrict")
// async UploadFileSQLFamillyMother( @UseInterceptors(FileInterceptor("file"))
// @UploadedFile() file: Express.Multer.File, async ImportSubDistrict(
// @Request() request: { user: Record<string, any> }, @UploadedFile() file: Express.Multer.File,
// ) { @Request() request: { user: Record<string, any> },
// const workbook = xlsx.read(file.buffer, { type: "buffer" }); ) {
// const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet const workbook = xlsx.read(file.buffer, { type: "buffer" });
// const sheet = workbook.Sheets[sheetName]; const sheetName = workbook.SheetNames[0];
// const getProFile = xlsx.utils.sheet_to_json(sheet); const sheet = workbook.Sheets[sheetName];
// let profiles: any = []; const getExcel = xlsx.utils.sheet_to_json(sheet);
// await Promise.all( let subDistrict_: any = [];
// getProFile.map(async (item: any) => {
// // Create a new Profile entity and assign fields from the parsed data await Promise.all(
getExcel.map(async (item: any) => {
// const profile = new ProfileFamilyMother(); const subD = new SubDistrictImport();
// // Check if the profile already exists subD.PROVINCE_CODE = item.PROVINCE_CODE;
// const existingProfile = await this.profileFamilyMotherRepository.findOne({ subD.AMPHUR_CODE = item.AMPHUR_CODE;
// where: { id: item["id"] }, subD.DISTRICT_CODE = item.DISTRICT_CODE;
// }); subD.DISTRICT_NAME = item.DISTRICT_NAME;
// // If profile exists, skip saving subD.createdUserId = request.user.sub;
// if (existingProfile) { subD.createdFullName = request.user.name;
// return; subD.lastUpdateUserId = request.user.sub;
// } subD.lastUpdateFullName = request.user.name;
// // Assign fields from the item to the profile entit subDistrict_.push(subD);
}),
// profile.id = item["id"] == "NULL" ? null : item["id"]; );
// // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); await this.subDistrictRepo.save(subDistrict_);
// profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; return new HttpSuccess(subDistrict_);
// // profile.lastUpdatedAt = }
// // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]);
// profile.lastUpdateUserId = /**
// item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; * @summary -
// profile.createdFullName = */
// item["createdFullName"] == "NULL" ? null : item["createdFullName"]; @Post("uploadProfileAddress-Officer")
// profile.lastUpdateFullName = @UseInterceptors(FileInterceptor("file"))
// item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; async UploadFileSQLAddress(
// profile.motherPrefix = item["motherPrefix"] == "NULL" ? null : item["motherPrefix"]; @UploadedFile() file: Express.Multer.File,
// profile.motherFirstName = @Request() request: { user: Record<string, any> },
// item["motherFirstName"] == "NULL" ? null : item["motherFirstName"]; ) {
// profile.motherLastName = item["motherLastName"] == "NULL" ? null : item["motherLastName"]; const workbook = xlsx.read(file.buffer, { type: "buffer" });
// profile.motherCareer = item["motherCareer"] == "NULL" ? null : item["motherCareer"]; const sheetName = workbook.SheetNames[0];
// profile.motherCitizenId = const sheet = workbook.Sheets[sheetName];
// item["motherCitizenId"] == "NULL" ? null : item["motherCitizenId"]; const getAddress = xlsx.utils.sheet_to_json(sheet);
// profile.motherLive = item["motherLive"] == "NULL" ? null : item["motherLive"]; let null_: any = null;
// profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; await Promise.all(
// profile.profileEmployeeId = getAddress.map(async (item: any) => {
// item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; let provinceRegis_: any = null;
// profiles.push(profile); let districtRegis_: any = null;
// }), let subDistrictRegis_: any = null;
// ); let provinceCurr_: any = null;
// await this.profileFamilyMotherRepository.save(profiles); let districtCurr_: any = null;
// return new HttpSuccess(getProFile); let subDistrictCurr_: any = null;
// } const existingProfile = await this.profileRepo.findOne({
where: { citizenId: item.ID },
// @Post("uploadSQLFamilly-Couple") });
// @UseInterceptors(FileInterceptor("file")) if (!existingProfile) {
// async UploadFileSQLFamillyCouple( return;
// @UploadedFile() file: Express.Multer.File, } else {
// // @Request() request: { user: Record<string, any> }, //registration address
// ) { if (item["PROVINCE_CODE"]) {
// const workbook = xlsx.read(file.buffer, { type: "buffer" }); provinceRegis_ = await this.provincsRepo.findOne({
// const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet where: { PROVINCE_CODE: item["PROVINCE_CODE"] },
// const sheet = workbook.Sheets[sheetName]; });
// const getProFile = xlsx.utils.sheet_to_json(sheet); if (provinceRegis_) {
// let profiles: any = []; let provinceId = await this.provinceIdRepo.findOne({
// await Promise.all( where: {
// getProFile.map(async (item: any) => { name: provinceRegis_.PROVINCE_NAME,
// // Create a new Profile entity and assign fields from the parsed data },
});
// const profile = new ProfileFamilyCouple(); existingProfile.registrationProvinceId = provinceId ? provinceId.id : null_;
// // Check if the profile already exists }
// const existingProfile = await this.profileFamilyCoupleRepository.findOne({ }
// where: { id: item["id"] }, if (item["AMPHUR_CODE"]) {
// }); districtRegis_ = await this.amphurRepo.findOne({
// // If profile exists, skip saving where: {
// if (existingProfile) { AMPHUR_CODE: item["AMPHUR_CODE"],
// return; PROVINCE_CODE: provinceRegis_.PROVINCE_CODE,
// } },
// // Assign fields from the item to the profile entit });
if (districtRegis_) {
// profile.id = item["id"] == "NULL" ? null : item["id"]; let districtId = await this.districtIdRepo.findOne({
// // profile.createdAt = item["createdAt"] == "NULL" ? null : new Date(item["createdAt"]); where: {
// profile.createdUserId = item["createdUserId"] == "NULL" ? null : item["createdUserId"]; name: districtRegis_.AMPHUR_NAME,
// // profile.lastUpdatedAt = },
// // item["lastUpdatedAt"] == "NULL" ? null : new Date(item["lastUpdatedAt"]); });
// profile.lastUpdateUserId = existingProfile.registrationDistrictId = districtId ? districtId.id : null_;
// item["lastUpdateUserId"] == "NULL" ? null : item["lastUpdateUserId"]; }
// profile.createdFullName = }
// item["createdFullName"] == "NULL" ? null : item["createdFullName"]; if (item["DISTRICT_CODE"]) {
// profile.lastUpdateFullName = subDistrictRegis_ = await this.subDistrictRepo.findOne({
// item["lastUpdateFullName"] == "NULL" ? null : item["lastUpdateFullName"]; where: {
// profile.couple = item["couple"] == "NULL" ? null : item["couple"]; DISTRICT_CODE: item["DISTRICT_CODE"],
// profile.couplePrefix = item["couplePrefix"] == "NULL" ? null : item["couplePrefix"]; AMPHUR_CODE: districtRegis_.AMPHUR_CODE,
// profile.coupleFirstName = PROVINCE_CODE: provinceRegis_.PROVINCE_CODE,
// item["coupleFirstName"] == "NULL" ? null : item["coupleFirstName"]; },
// profile.coupleLastName = item["coupleLastName"] == "NULL" ? null : item["coupleLastName"]; });
// profile.coupleLastNameOld = if (subDistrictRegis_) {
// item["coupleLastNameOld"] == "NULL" ? null : item["coupleLastNameOld"]; let subDistrictId = await this.subDistrictIdRepo.findOne({
// profile.coupleCareer = item["coupleCareer"] == "NULL" ? null : item["coupleCareer"]; where: {
// profile.coupleCitizenId = name: subDistrictRegis_.DISTRICT_NAME,
// item["coupleCitizenId"] == "NULL" ? null : item["coupleCitizenId"]; },
// profile.coupleLive = item["coupleLive"] == "NULL" ? null : item["coupleLive"]; });
// profile.relationship = item["relationship"] == "NULL" ? null : item["relationship"]; existingProfile.registrationSubDistrictId = subDistrictId ? subDistrictId.id : null_;
// profile.profileId = item["profileId"] == "NULL" ? null : item["profileId"]; }
// profile.profileEmployeeId = }
// item["profileEmployeeId"] == "NULL" ? null : item["profileEmployeeId"]; //current address
// profiles.push(profile); if (item["CONTACT_PROVINCE_CODE"]) {
// }), provinceCurr_ = await this.provincsRepo.findOne({
// ); where: { PROVINCE_CODE: item["CONTACT_PROVINCE_CODE"] },
// await this.profileFamilyCoupleRepository.save(profiles); });
// return new HttpSuccess(getProFile); 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();
}
/**
* @summary -
*/
@Post("uploadProfileAddress-Employee")
@UseInterceptors(FileInterceptor("file"))
async UploadFileSQLAddressEmp(
@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 getAddress = xlsx.utils.sheet_to_json(sheet);
let null_: any = null;
await Promise.all(
getAddress.map(async (item: any) => {
let provinceRegis_: any = null;
let districtRegis_: any = null;
let subDistrictRegis_: any = null;
let provinceCurr_: any = null;
let districtCurr_: any = null;
let subDistrictCurr_: any = null;
const existingProfileEmp = await this.profileEmpRepo.findOne({
where: { citizenId: item.ID },
});
if (!existingProfileEmp) {
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,
},
});
existingProfileEmp.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,
},
});
existingProfileEmp.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,
},
});
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,13 +1,12 @@
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;
@ -15,10 +14,15 @@ class Extension {
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;
} }

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\``);
}
}