diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index ff378dc5..c0952255 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -14,7 +14,7 @@ import { UploadedFile, } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { Brackets, Double } from "typeorm"; +import { Brackets, Double, In, Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; @@ -336,19 +336,20 @@ export class ImportDataController extends Controller { profileSalary.createdFullName = request.user.name; profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateFullName = request.user.name; - profileSalarys.push(profileSalary); + // profileSalarys.push(profileSalary); // await this.salaryRepository.save(profileSalary); - if (profileSalarys.length === BATCH_SIZE) { - await this.salaryRepository.save(profileSalarys); - profileSalarys = await []; - } + // if (profileSalarys.length === BATCH_SIZE) { + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.salaryRepository.save(profileSalary); + // profileSalarys = await []; + // } }), ); // await this.salaryRepository.save(profileSalarys); // profileSalarys = await []; }), ); - await this.salaryRepository.save(profileSalarys); + // await this.salaryRepository.save(profileSalarys); // } console.log(rowCount); return new HttpSuccess(); @@ -427,13 +428,13 @@ export class ImportDataController extends Controller { profileSalary.createdFullName = request.user.name; profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateFullName = request.user.name; - profileSalarys.push(profileSalary); + // profileSalarys.push(profileSalary); // await this.salaryRepository.save(profileSalary); - if (profileSalarys.length === BATCH_SIZE) { - await this.salaryRepository.save(profileSalarys); - profileSalarys = await []; - } + // if (profileSalarys.length === BATCH_SIZE) { console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.salaryRepository.save(profileSalary); + // profileSalarys = await []; + // } }), ); // await this.salaryRepository.save(profileSalarys); @@ -441,7 +442,7 @@ export class ImportDataController extends Controller { }), ); // } - await this.salaryRepository.save(profileSalarys); + // await this.salaryRepository.save(profileSalarys); console.log(rowCount); return new HttpSuccess(); } @@ -550,7 +551,7 @@ export class ImportDataController extends Controller { }), ); // } - console.log(rowCount); + // console.log(rowCount); // await Promise.all([ // this.profileFamilyFatherRepository.save(fathers), @@ -665,7 +666,7 @@ export class ImportDataController extends Controller { }), ); // } - console.log(rowCount); + // console.log(rowCount); // await Promise.all([ // this.profileFamilyFatherRepository.save(fathers), @@ -768,6 +769,7 @@ export class ImportDataController extends Controller { education.lastUpdateUserId = request.user.sub; education.lastUpdateFullName = request.user.name; // await educations.push(await education); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); await this.educationRepository.save(await education); }), ); @@ -776,7 +778,7 @@ export class ImportDataController extends Controller { }), ); // } - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); // await this.educationRepository.save(educations); return new HttpSuccess(); } @@ -840,14 +842,16 @@ export class ImportDataController extends Controller { education.createdFullName = request.user.name; education.lastUpdateUserId = request.user.sub; education.lastUpdateFullName = request.user.name; - educations.push(education); + // educations.push(education); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.educationRepository.save(education); }), ); - await this.educationRepository.save(educations); + // await this.educationRepository.save(educations); }), ); // } - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); // await this.educationRepository.save(educations); return new HttpSuccess(); } @@ -1086,15 +1090,18 @@ export class ImportDataController extends Controller { _item.registrationZipCode = existingProfile.ZIPCODE; _item.currentAddress = existingProfile.CONTACT_H_NUMBER; _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; + _item.createdUserId = request.user.sub; + _item.createdFullName = request.user.name; _item.lastUpdateUserId = request.user.sub; _item.lastUpdateFullName = request.user.name; // profileDatas.push(_item); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); await this.profileRepo.save(_item); }), ); // await this.profileRepo.save(profileDatas); // } - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); return new HttpSuccess(); } @@ -1152,7 +1159,7 @@ export class ImportDataController extends Controller { _item.registrationProvinceId = provinceId ? provinceId.id : null_; } } - if (existingProfile.AMPHUR_CODE) { + if (existingProfile.AMPHUR_CODE && provinceRegis_) { districtRegis_ = await this.amphurRepo.findOne({ where: { AMPHUR_CODE: existingProfile.AMPHUR_CODE, @@ -1168,7 +1175,7 @@ export class ImportDataController extends Controller { _item.registrationDistrictId = districtId ? districtId.id : null_; } } - if (existingProfile.DISTRICT_CODE) { + if (existingProfile.DISTRICT_CODE && districtRegis_ && provinceRegis_) { subDistrictRegis_ = await this.subDistrictRepo.findOne({ where: { DISTRICT_CODE: existingProfile.DISTRICT_CODE, @@ -1199,7 +1206,7 @@ export class ImportDataController extends Controller { _item.currentProvinceId = provinceId ? provinceId.id : null_; } } - if (existingProfile.CONTACT_AMPHUR_CODE) { + if (existingProfile.CONTACT_AMPHUR_CODE && provinceCurr_) { districtCurr_ = await this.amphurRepo.findOne({ where: { AMPHUR_CODE: existingProfile.CONTACT_AMPHUR_CODE, @@ -1215,7 +1222,7 @@ export class ImportDataController extends Controller { _item.currentDistrictId = districtId ? districtId.id : null_; } } - if (existingProfile.CONTACT_DISTRICT_CODE) { + if (existingProfile.CONTACT_DISTRICT_CODE && districtCurr_ && provinceCurr_) { subDistrictCurr_ = await this.subDistrictRepo.findOne({ where: { DISTRICT_CODE: existingProfile.CONTACT_DISTRICT_CODE, @@ -1236,15 +1243,79 @@ export class ImportDataController extends Controller { _item.registrationZipCode = existingProfile.ZIPCODE; _item.currentAddress = existingProfile.CONTACT_H_NUMBER; _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; + _item.createdUserId = request.user.sub; + _item.createdFullName = request.user.name; _item.lastUpdateUserId = request.user.sub; _item.lastUpdateFullName = request.user.name; // profileDatas.push(_item); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); await this.profileEmpRepo.save(_item); }), ); // await this.profileEmpRepo.save(profileDatas); // } - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + return new HttpSuccess(); + } + /** + * @summary ทะเบียนประวัติ ข้าราชการ + */ + @Post("cleardataupload") + async ClearDataUpload(@Request() request: { user: Record }) { + const profileOff = await this.profileRepo.find({ + select: ["citizenId"], + }); + const profileEmp = await this.profileEmpRepo.find({ + select: ["citizenId"], + }); + const _profileOff = profileOff.map((x) => x.citizenId); + const _profileEmp = profileEmp.map((x) => x.citizenId); + const allId = _profileOff.concat(_profileEmp); + + for (var i = 1; i <= 1000; i++) { + const HR_POSITION_OFFICER = await this.HR_POSITION_OFFICERRepo.find({ + where: { CIT: Not(In(allId)) }, + take: 1000, + skip: 0, + }); + this.HR_POSITION_OFFICERRepo.remove(HR_POSITION_OFFICER); + // const HR_PERSONAL_OFFICER_FAMILY = await this.HR_PERSONAL_OFFICER_FAMILYRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_PERSONAL_OFFICER_FAMILYRepo.remove(HR_PERSONAL_OFFICER_FAMILY); + // const HR_EDUCATION = await this.HR_EDUCATIONRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_EDUCATIONRepo.remove(HR_EDUCATION); + // const HR_PERSONAL_OFFICER_ADDRESS = await this.HR_PERSONAL_OFFICER_ADDRESSRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_PERSONAL_OFFICER_ADDRESSRepo.remove(HR_PERSONAL_OFFICER_ADDRESS); + // const HR_EDUCATION_EMP = await this.HR_EDUCATION_EMPRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_EDUCATION_EMPRepo.remove(HR_EDUCATION_EMP); + // const HR_PERSONAL_EMP_ADDRESS = await this.HR_PERSONAL_EMP_ADDRESSRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_PERSONAL_EMP_ADDRESSRepo.remove(HR_PERSONAL_EMP_ADDRESS); + // const HR_PERSONAL_EMP_FAMILY = await this.HR_PERSONAL_EMP_FAMILYRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_PERSONAL_EMP_FAMILYRepo.remove(HR_PERSONAL_EMP_FAMILY); + } return new HttpSuccess(); } } diff --git a/src/entities/HR_EDUCATION.ts b/src/entities/HR_EDUCATION.ts index 64fe5602..0bf28924 100644 --- a/src/entities/HR_EDUCATION.ts +++ b/src/entities/HR_EDUCATION.ts @@ -32,12 +32,12 @@ export class HR_EDUCATION { }) EDUCATION_YEAR: string; - @Column({ - nullable: true, - type: "text", - default: null, - }) - EDUCATION_NAME: string; + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // EDUCATION_NAME: string; @Column({ nullable: true, diff --git a/src/entities/HR_EDUCATION_EMP.ts b/src/entities/HR_EDUCATION_EMP.ts index 7dc106d4..ea6f6e42 100644 --- a/src/entities/HR_EDUCATION_EMP.ts +++ b/src/entities/HR_EDUCATION_EMP.ts @@ -32,12 +32,12 @@ export class HR_EDUCATION_EMP { }) EDUCATION_YEAR: string; - @Column({ - nullable: true, - type: "text", - default: null, - }) - EDUCATION_NAME: string; + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // EDUCATION_NAME: string; @Column({ nullable: true,