From 603602adbce8d60895eea37483fad53072e78ef7 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 31 Jul 2024 09:43:23 +0700 Subject: [PATCH] no message --- src/controllers/ImportDataController.ts | 1378 ++++++++++++----------- src/controllers/PermissionController.ts | 8 +- 2 files changed, 696 insertions(+), 690 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 3e4f50fb..7412d2cd 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -109,18 +109,18 @@ export class ImportDataController extends Controller { let type_: any = null; let level_: any = null; const profile = new Profile(); - const existingProfile = await this.profileRepo.findOne({ - where: { citizenId: item["ID"] }, - }); - if (existingProfile) { - continue; - } if (item["FLAG_RETIRE_STATUS"] != "" && item["FLAG_RETIRE_STATUS"] != null) { continue; } if (item["FLAG_PERSON_TYPE"] != "1") { continue; } + const existingProfile = await this.profileRepo.findOne({ + where: { citizenId: item["ID"] }, + }); + if (existingProfile) { + continue; + } if (item["MP_CEE_TYPE"]) { type_ = await this.posTypeRepo.findOne({ @@ -180,7 +180,7 @@ export class ImportDataController extends Controller { if (profiles.length === BATCH_SIZE) { await this.profileRepo.save(profiles); - profiles = []; + profiles = await []; if (global.gc) { global.gc(); } @@ -208,18 +208,18 @@ export class ImportDataController extends Controller { for await (const item of readStream) { rowCount++; const profileEmp = new ProfileEmployee(); - const existingProfile = await this.profileEmpRepo.findOne({ - where: { citizenId: item["ID"] }, - }); - console.log(item); - console.log(item["ID"]); - // console.log(existingProfile); - if (existingProfile) { + if (item["FLAG_RETIRE_STATUS"] != "" && item["FLAG_RETIRE_STATUS"] != null) { continue; } if (item["FLAG_PERSON_TYPE"] != "6") { continue; } + const existingProfile = await this.profileEmpRepo.findOne({ + where: { citizenId: item["ID"] }, + }); + if (existingProfile) { + continue; + } let dateRetire = Extension.ConvertToDateTime(item["MP_FORCE_DATE"]); @@ -248,19 +248,19 @@ export class ImportDataController extends Controller { profileEmp.createdFullName = request.user.name; profileEmp.lastUpdateUserId = request.user.sub; profileEmp.lastUpdateFullName = request.user.name; - profiles.push(profileEmp); + // profiles.push(profileEmp); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - if (profiles.length === BATCH_SIZE) { - await this.profileEmpRepo.save(profiles); - profiles = []; - if (global.gc) { - global.gc(); - } - } + // if (profiles.length === BATCH_SIZE) { + await this.profileEmpRepo.save(profileEmp); + // profiles = await []; + // if (global.gc) { + // global.gc(); + // } + // } } console.log(rowCount); - await this.profileEmpRepo.save(profiles); + // await this.profileEmpRepo.save(profiles); return new HttpSuccess(); } @@ -273,76 +273,85 @@ export class ImportDataController extends Controller { let profileSalarys: any = []; let null_: any = null; - const [_profiles, total] = await AppDataSource.getRepository(Profile) + const [profiles, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") - .select(["profile.id"]) + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + // .skip(0) + // .take(20) .getManyAndCount(); - for (var i = 1; i <= total / BATCH_SIZE; i++) { - const profiles = await AppDataSource.getRepository(Profile) - .createQueryBuilder("profile") - .select(["profile.citizenId", "profile.id"]) - .orderBy("profile.citizenId", "ASC") - .skip((i - 1) * BATCH_SIZE) - .take(BATCH_SIZE) - .getMany(); + // for (var i = 1; i <= total / BATCH_SIZE; i++) { + // const profiles = await AppDataSource.getRepository(Profile) + // .createQueryBuilder("profile") + // .select(["profile.citizenId", "profile.id"]) + // .orderBy("profile.citizenId", "ASC") + // .skip((i - 1) * BATCH_SIZE) + // .take(BATCH_SIZE) + // .getMany(); - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "MP_POS_DATE", - "SALARY", - "MP_COMMAND_NUM", - "POS_NUM_NAME", - "POS_NUM_CODE", - "FLAG_TO_NAME", - "WORK_LINE_NAME", - "SPECIALIST_NAME", - "ADMIN_NAME", - "REMARK", - "ORDER_MOVE_POSITION", - ], - }); + await Promise.all( + profiles.map(async (_item) => { + const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ + where: { CIT: _item.citizenId }, + select: [ + "CIT", + "MP_POS_DATE", + "SALARY", + "MP_COMMAND_NUM", + "POS_NUM_NAME", + "POS_NUM_CODE", + "FLAG_TO_NAME", + "WORK_LINE_NAME", + "SPECIALIST_NAME", + "ADMIN_NAME", + "REMARK", + "ORDER_MOVE_POSITION", + ], + }); - profileSalarys = await []; - await Promise.all( - existingProfile.map(async (item) => { - rowCount++; - const profileSalary = new ProfileSalary(); - profileSalary.date = - item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); - const SALARY: any = - item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); - profileSalary.amount = SALARY; - profileSalary.profileId = _item.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; - const ORDER_MOVE_POSITION: any = - item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == "" - ? null_ - : Number(item.ORDER_MOVE_POSITION); - profileSalary.order = 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); - profileSalarys = []; - }), - ); - } + // profileSalarys = await []; + await Promise.all( + existingProfile.map(async (item) => { + rowCount++; + const profileSalary = new ProfileSalary(); + profileSalary.date = + item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); + const SALARY: any = + item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); + profileSalary.amount = SALARY; + profileSalary.profileId = _item.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; + const ORDER_MOVE_POSITION: any = + item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == "" + ? null_ + : Number(item.ORDER_MOVE_POSITION); + profileSalary.order = 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(profileSalary); + if (profiles.length === BATCH_SIZE) { + await this.salaryRepository.save(profileSalarys); + profileSalarys = await []; + } + }), + ); + // await this.salaryRepository.save(profileSalarys); + // profileSalarys = await []; + }), + ); + await this.salaryRepository.save(profileSalarys); + // } console.log(rowCount); - return new HttpSuccess(profileSalarys); + return new HttpSuccess(); } /** @@ -354,78 +363,86 @@ export class ImportDataController extends Controller { let profileSalarys: any = []; let null_: any = null; - const [_profiles, total] = await AppDataSource.getRepository(ProfileEmployee) + const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) .createQueryBuilder("profile") - .select(["profile.id"]) + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + // .skip(0) + // .take(20) .getManyAndCount(); - for (var i = 1; i <= total / BATCH_SIZE; i++) { - const profiles = await AppDataSource.getRepository(ProfileEmployee) - .createQueryBuilder("profile") - .select(["profile.citizenId", "profile.id"]) - .orderBy("profile.citizenId", "ASC") - .skip((i - 1) * BATCH_SIZE) - .take(BATCH_SIZE) - .getMany(); + // for (var i = 1; i <= total / BATCH_SIZE; i++) { + // const profiles = await AppDataSource.getRepository(ProfileEmployee) + // .createQueryBuilder("profile") + // .select(["profile.citizenId", "profile.id"]) + // .orderBy("profile.citizenId", "ASC") + // .skip((i - 1) * BATCH_SIZE) + // .take(BATCH_SIZE) + // .getMany(); - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "MP_POS_DATE", - "SALARY", - "MP_COMMAND_NUM", - "POS_NUM_NAME", - "POS_NUM_CODE", - "FLAG_TO_NAME", - "WORK_LINE_NAME", - "SPECIALIST_NAME", - "ADMIN_NAME", - "REMARK", - "ORDER_MOVE_POSITION", - ], - }); + await Promise.all( + profiles.map(async (_item) => { + const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ + where: { CIT: _item.citizenId }, + select: [ + "CIT", + "MP_POS_DATE", + "SALARY", + "MP_COMMAND_NUM", + "POS_NUM_NAME", + "POS_NUM_CODE", + "FLAG_TO_NAME", + "WORK_LINE_NAME", + "SPECIALIST_NAME", + "ADMIN_NAME", + "REMARK", + "ORDER_MOVE_POSITION", + ], + }); - profileSalarys = await []; - await Promise.all( - existingProfile.map(async (item) => { - rowCount++; - const profileSalary = new ProfileSalary(); + profileSalarys = await []; + await Promise.all( + existingProfile.map(async (item) => { + rowCount++; + const profileSalary = new ProfileSalary(); - profileSalary.date = - item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); - const SALARY: any = - item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); - profileSalary.amount = SALARY; - profileSalary.profileEmployeeId = _item.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; - const ORDER_MOVE_POSITION: any = - item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == "" - ? null_ - : Number(item.ORDER_MOVE_POSITION); - profileSalary.order = 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); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - }), - ); - await this.salaryRepository.save(profileSalarys); - profileSalarys = []; - }), - ); - } - console.log(rowCount); + profileSalary.date = + item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); + const SALARY: any = + item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); + profileSalary.amount = SALARY; + profileSalary.profileEmployeeId = _item.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; + const ORDER_MOVE_POSITION: any = + item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == "" + ? null_ + : Number(item.ORDER_MOVE_POSITION); + profileSalary.order = 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(profileSalary); + if (profileSalarys.length === BATCH_SIZE) { + await this.salaryRepository.save(profileSalarys); + profileSalarys = await []; + } + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + }), + ); + // await this.salaryRepository.save(profileSalarys); + // profileSalarys = await []; + }), + ); + // } await this.salaryRepository.save(profileSalarys); + console.log(rowCount); return new HttpSuccess(); } @@ -439,123 +456,107 @@ export class ImportDataController extends Controller { let mothers: any = []; let couples: any = []; - const [_profiles, total] = await AppDataSource.getRepository(Profile) + const [profiles, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") - .select(["profile.id"]) + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + // .skip(0) + // .take(20) .getManyAndCount(); - for (var i = 1; i <= total / BATCH_SIZE; i++) { - const profiles = await AppDataSource.getRepository(Profile) - .createQueryBuilder("profile") - .select(["profile.citizenId", "profile.id"]) - .orderBy("profile.citizenId", "ASC") - .skip((i - 1) * BATCH_SIZE) - .take(BATCH_SIZE) - .getMany(); + // for (var i = 1; i <= total / BATCH_SIZE; i++) { + // const profiles = await AppDataSource.getRepository(Profile) + // .createQueryBuilder("profile") + // .select(["profile.citizenId", "profile.id"]) + // .orderBy("profile.citizenId", "ASC") + // .skip((i - 1) * BATCH_SIZE) + // .take(BATCH_SIZE) + // .getMany(); - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_PERSONAL_OFFICER_FAMILYRepo.findOne({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "FATHER_RANK_NAME", - "FATHER_FNAME", - "FATHER_LNAME", - "MOTHER_RANK_NAME", - "MOTHER_FNAME", - "MOTHER_LNAME", - "SPOUSE_RANK_NAME", - "SPOUSE_FNAME", - "SPOUSE_LNAME", - "SPOUSE_ID", - "MARRIAGE_STATE", - ], - }); - if (!existingProfile) { - return; - } + await Promise.all( + profiles.map(async (_item) => { + const existingProfile = await this.HR_PERSONAL_OFFICER_FAMILYRepo.findOne({ + where: { CIT: _item.citizenId }, + select: [ + "CIT", + "FATHER_RANK_NAME", + "FATHER_FNAME", + "FATHER_LNAME", + "MOTHER_RANK_NAME", + "MOTHER_FNAME", + "MOTHER_LNAME", + "SPOUSE_RANK_NAME", + "SPOUSE_FNAME", + "SPOUSE_LNAME", + "SPOUSE_ID", + "MARRIAGE_STATE", + ], + }); + if (!existingProfile) { + return; + } - // fathers = await []; - // mothers = await []; - // couples = await []; - // await Promise.all( - // existingProfile.map(async (item) => { - rowCount++; - const profileFather = new ProfileFamilyFather(); - const profileMother = new ProfileFamilyMother(); - const profileCouple = new ProfileFamilyCouple(); + rowCount++; + const profileFather = new ProfileFamilyFather(); + const profileMother = new ProfileFamilyMother(); + const profileCouple = new ProfileFamilyCouple(); - profileFather.profileId = _item.id; - profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; - profileFather.fatherFirstName = existingProfile.FATHER_FNAME; - profileFather.fatherLastName = existingProfile.FATHER_LNAME; - profileFather.createdUserId = request.user.sub; - profileFather.createdFullName = request.user.name; - profileFather.lastUpdateUserId = request.user.sub; - profileFather.lastUpdateFullName = request.user.name; + profileFather.profileId = _item.id; + profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; + profileFather.fatherFirstName = existingProfile.FATHER_FNAME; + profileFather.fatherLastName = existingProfile.FATHER_LNAME; + profileFather.createdUserId = request.user.sub; + profileFather.createdFullName = request.user.name; + profileFather.lastUpdateUserId = request.user.sub; + profileFather.lastUpdateFullName = request.user.name; - profileMother.profileId = _item.id; - profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; - profileMother.motherFirstName = existingProfile.MOTHER_FNAME; - profileMother.motherLastName = existingProfile.MOTHER_LNAME; - profileMother.createdUserId = request.user.sub; - profileMother.createdFullName = request.user.name; - profileMother.lastUpdateUserId = request.user.sub; - profileMother.lastUpdateFullName = request.user.name; + profileMother.profileId = _item.id; + profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; + profileMother.motherFirstName = existingProfile.MOTHER_FNAME; + profileMother.motherLastName = existingProfile.MOTHER_LNAME; + profileMother.createdUserId = request.user.sub; + profileMother.createdFullName = request.user.name; + profileMother.lastUpdateUserId = request.user.sub; + profileMother.lastUpdateFullName = request.user.name; - profileCouple.profileId = _item.id; - profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; - profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; - profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; - profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; - profileCouple.relationship = existingProfile.MARRIAGE_STATE; - // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; - profileCouple.createdUserId = request.user.sub; - profileCouple.createdFullName = request.user.name; - profileCouple.lastUpdateUserId = request.user.sub; - profileCouple.lastUpdateFullName = request.user.name; + profileCouple.profileId = _item.id; + profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; + profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; + profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; + profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; + profileCouple.relationship = existingProfile.MARRIAGE_STATE; + // profileCouple.coupleLive = existingProfile.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); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // fathers.push(profileFather); + // mothers.push(profileMother); + // couples.push(profileCouple); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - if (fathers.length === BATCH_SIZE) { - await this.profileFamilyFatherRepository.save(fathers); - fathers = await []; - // if (global.gc) { - // global.gc(); - // } - } - if (mothers.length === BATCH_SIZE) { - await this.profileFamilyMotherRepository.save(mothers); - mothers = await []; - // if (global.gc) { - // global.gc(); - // } - } - if (couples.length === BATCH_SIZE) { - await this.profileFamilyCoupleRepository.save(couples); - couples = await []; - // if (global.gc) { - // global.gc(); - // } - } - // }), - // ); - // await this.salaryRepository.save(profileSalarys); - // profileSalarys = []; - }), - ); - } + // if (fathers.length === BATCH_SIZE) { + await this.profileFamilyFatherRepository.save(profileFather); + // fathers = await []; + // } + // if (mothers.length === BATCH_SIZE) { + await this.profileFamilyMotherRepository.save(profileMother); + // mothers = await []; + // } + // if (couples.length === BATCH_SIZE) { + await this.profileFamilyCoupleRepository.save(profileCouple); + // couples = await []; + // } + }), + ); // } console.log(rowCount); - await Promise.all([ - this.profileFamilyFatherRepository.save(fathers), - this.profileFamilyMotherRepository.save(mothers), - this.profileFamilyCoupleRepository.save(couples), - ]); + // await Promise.all([ + // this.profileFamilyFatherRepository.save(fathers), + // this.profileFamilyMotherRepository.save(mothers), + // this.profileFamilyCoupleRepository.save(couples), + // ]); return new HttpSuccess(); } @@ -570,104 +571,107 @@ export class ImportDataController extends Controller { let mothers: any = []; let couples: any = []; - const [_profiles, total] = await AppDataSource.getRepository(ProfileEmployee) + const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) .createQueryBuilder("profile") - .select(["profile.id"]) + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + // .skip(0) + // .take(20) .getManyAndCount(); - for (var i = 1; i <= total / BATCH_SIZE; i++) { - const profiles = await AppDataSource.getRepository(ProfileEmployee) - .createQueryBuilder("profile") - .select(["profile.citizenId", "profile.id"]) - .orderBy("profile.citizenId", "ASC") - .skip((i - 1) * BATCH_SIZE) - .take(BATCH_SIZE) - .getMany(); + // for (var i = 1; i <= total / BATCH_SIZE; i++) { + // const profiles = await AppDataSource.getRepository(ProfileEmployee) + // .createQueryBuilder("profile") + // .select(["profile.citizenId", "profile.id"]) + // .orderBy("profile.citizenId", "ASC") + // .skip((i - 1) * BATCH_SIZE) + // .take(BATCH_SIZE) + // .getMany(); - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_PERSONAL_OFFICER_FAMILYRepo.findOne({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "FATHER_RANK_NAME", - "FATHER_FNAME", - "FATHER_LNAME", - "MOTHER_RANK_NAME", - "MOTHER_FNAME", - "MOTHER_LNAME", - "SPOUSE_RANK_NAME", - "SPOUSE_FNAME", - "SPOUSE_LNAME", - "SPOUSE_ID", - "MARRIAGE_STATE", - ], - }); - if (!existingProfile) { - return; - } + await Promise.all( + profiles.map(async (_item) => { + const existingProfile = await this.HR_PERSONAL_OFFICER_FAMILYRepo.findOne({ + where: { CIT: _item.citizenId }, + select: [ + "CIT", + "FATHER_RANK_NAME", + "FATHER_FNAME", + "FATHER_LNAME", + "MOTHER_RANK_NAME", + "MOTHER_FNAME", + "MOTHER_LNAME", + "SPOUSE_RANK_NAME", + "SPOUSE_FNAME", + "SPOUSE_LNAME", + "SPOUSE_ID", + "MARRIAGE_STATE", + ], + }); + if (!existingProfile) { + return; + } - rowCount++; - const profileFather = new ProfileFamilyFather(); - const profileMother = new ProfileFamilyMother(); - const profileCouple = new ProfileFamilyCouple(); + rowCount++; + const profileFather = new ProfileFamilyFather(); + const profileMother = new ProfileFamilyMother(); + const profileCouple = new ProfileFamilyCouple(); - profileFather.profileEmployeeId = _item.id; - profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; - profileFather.fatherFirstName = existingProfile.FATHER_FNAME; - profileFather.fatherLastName = existingProfile.FATHER_LNAME; - profileFather.createdUserId = request.user.sub; - profileFather.createdFullName = request.user.name; - profileFather.lastUpdateUserId = request.user.sub; - profileFather.lastUpdateFullName = request.user.name; + profileFather.profileEmployeeId = _item.id; + profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; + profileFather.fatherFirstName = existingProfile.FATHER_FNAME; + profileFather.fatherLastName = existingProfile.FATHER_LNAME; + profileFather.createdUserId = request.user.sub; + profileFather.createdFullName = request.user.name; + profileFather.lastUpdateUserId = request.user.sub; + profileFather.lastUpdateFullName = request.user.name; - profileMother.profileEmployeeId = _item.id; - profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; - profileMother.motherFirstName = existingProfile.MOTHER_FNAME; - profileMother.motherLastName = existingProfile.MOTHER_LNAME; - profileMother.createdUserId = request.user.sub; - profileMother.createdFullName = request.user.name; - profileMother.lastUpdateUserId = request.user.sub; - profileMother.lastUpdateFullName = request.user.name; + profileMother.profileEmployeeId = _item.id; + profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; + profileMother.motherFirstName = existingProfile.MOTHER_FNAME; + profileMother.motherLastName = existingProfile.MOTHER_LNAME; + profileMother.createdUserId = request.user.sub; + profileMother.createdFullName = request.user.name; + profileMother.lastUpdateUserId = request.user.sub; + profileMother.lastUpdateFullName = request.user.name; - profileCouple.profileEmployeeId = _item.id; - profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; - profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; - profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; - profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; - profileCouple.relationship = existingProfile.MARRIAGE_STATE; - // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; - profileCouple.createdUserId = request.user.sub; - profileCouple.createdFullName = request.user.name; - profileCouple.lastUpdateUserId = request.user.sub; - profileCouple.lastUpdateFullName = request.user.name; + profileCouple.profileEmployeeId = _item.id; + profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; + profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; + profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; + profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; + profileCouple.relationship = existingProfile.MARRIAGE_STATE; + // profileCouple.coupleLive = existingProfile.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); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // fathers.push(profileFather); + // mothers.push(profileMother); + // couples.push(profileCouple); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - if (fathers.length === BATCH_SIZE) { - await this.profileFamilyFatherRepository.save(fathers); - fathers = await []; - } - if (mothers.length === BATCH_SIZE) { - await this.profileFamilyMotherRepository.save(mothers); - mothers = await []; - } - if (couples.length === BATCH_SIZE) { - await this.profileFamilyCoupleRepository.save(couples); - couples = await []; - } - }), - ); - } + // if (fathers.length === BATCH_SIZE) { + await this.profileFamilyFatherRepository.save(profileFather); + // fathers = await []; + // } + // if (mothers.length === BATCH_SIZE) { + await this.profileFamilyMotherRepository.save(profileMother); + // mothers = await []; + // } + // if (couples.length === BATCH_SIZE) { + await this.profileFamilyCoupleRepository.save(profileCouple); + // couples = await []; + // } + }), + ); + // } console.log(rowCount); - await Promise.all([ - this.profileFamilyFatherRepository.save(fathers), - this.profileFamilyMotherRepository.save(mothers), - this.profileFamilyCoupleRepository.save(couples), - ]); + // await Promise.all([ + // this.profileFamilyFatherRepository.save(fathers), + // this.profileFamilyMotherRepository.save(mothers), + // this.profileFamilyCoupleRepository.save(couples), + // ]); return new HttpSuccess(); } @@ -712,68 +716,66 @@ export class ImportDataController extends Controller { let rowCount = 0; let educations: any = []; let null_: any = null; - const [_profiles, total] = await AppDataSource.getRepository(Profile) + const [profiles, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") - .select(["profile.id"]) + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + // .skip(0) + // .take(20) .getManyAndCount(); - for (var i = 1; i <= total / BATCH_SIZE; i++) { - const profiles = await AppDataSource.getRepository(Profile) - .createQueryBuilder("profile") - .select(["profile.citizenId", "profile.id"]) - .orderBy("profile.citizenId", "ASC") - .skip((i - 1) * BATCH_SIZE) - .take(BATCH_SIZE) - .getMany(); + // for (var i = 1; i <= 2; i++) { + // const profiles = await AppDataSource.getRepository(Profile) + // .createQueryBuilder("profile") + // .select(["profile.citizenId", "profile.id"]) + // .orderBy("profile.citizenId", "ASC") + // .skip((i - 1) * 5) + // .take(5) + // .getMany(); - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_EDUCATIONRepo.find({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "EDUCATION_CODE", - "START_EDUCATION_YEAR", - "EDUCATION_YEAR", - "EDUCATION_NAME", - "INSTITUE", - ], - }); + await Promise.all( + profiles.map(async (_item) => { + const existingProfile = await this.HR_EDUCATIONRepo.find({ + where: { CIT: _item.citizenId }, + select: ["CIT", "EDUCATION_CODE", "START_EDUCATION_YEAR", "EDUCATION_YEAR", "INSTITUE"], + }); - educations = await []; - await Promise.all( - existingProfile.map(async (item) => { - rowCount++; - const education = new ProfileEducation(); - const educationCode = await this.educationMisRepo.findOne({ - where: { EDUCATION_CODE: item.EDUCATION_CODE }, - }); + // educations = await []; + await Promise.all( + existingProfile.map(async (item) => { + rowCount++; + const education = new ProfileEducation(); + const educationCode = await this.educationMisRepo.findOne({ + where: { EDUCATION_CODE: item.EDUCATION_CODE }, + }); - let startDate = item.START_EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) - : null_; - startDate = startDate ? new Date(startDate, 0, 1) : null_; + let startDate = item.START_EDUCATION_YEAR + ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) + : null_; + startDate = startDate ? new Date(startDate, 0, 1) : null_; - let endDate = item.EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.EDUCATION_YEAR) - : null_; - endDate = endDate ? new Date(endDate, 0, 1) : null_; + let endDate = item.EDUCATION_YEAR + ? Extension.ConvertToDateTime(item.EDUCATION_YEAR) + : null_; + endDate = endDate ? new Date(endDate, 0, 1) : null_; - education.profileId = _item.id; - education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; - education.institute = item.INSTITUE; - education.startDate = startDate; - education.endDate = endDate; - education.createdUserId = request.user.sub; - education.createdFullName = request.user.name; - education.lastUpdateUserId = request.user.sub; - education.lastUpdateFullName = request.user.name; - educations.push(education); - }), - ); - await this.educationRepository.save(educations); - }), - ); - } + education.profileId = _item.id; + education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; + education.institute = item.INSTITUE; + education.startDate = startDate; + education.endDate = endDate; + education.createdUserId = request.user.sub; + education.createdFullName = request.user.name; + education.lastUpdateUserId = request.user.sub; + education.lastUpdateFullName = request.user.name; + // await educations.push(await education); + await this.educationRepository.save(await education); + }), + ); + // await this.educationRepository.save(educations); + // educations = await []; + }), + ); + // } console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); // await this.educationRepository.save(educations); return new HttpSuccess(); @@ -787,68 +789,64 @@ export class ImportDataController extends Controller { let rowCount = 0; let educations: any = []; let null_: any = null; - const [_profiles, total] = await AppDataSource.getRepository(ProfileEmployee) + const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) .createQueryBuilder("profile") - .select(["profile.id"]) + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + // .skip(0) + // .take(20) .getManyAndCount(); - for (var i = 1; i <= total / BATCH_SIZE; i++) { - const profiles = await AppDataSource.getRepository(ProfileEmployee) - .createQueryBuilder("profile") - .select(["profile.citizenId", "profile.id"]) - .orderBy("profile.citizenId", "ASC") - .skip((i - 1) * BATCH_SIZE) - .take(BATCH_SIZE) - .getMany(); + // for (var i = 1; i <= total / BATCH_SIZE; i++) { + // const profiles = await AppDataSource.getRepository(ProfileEmployee) + // .createQueryBuilder("profile") + // .select(["profile.citizenId", "profile.id"]) + // .orderBy("profile.citizenId", "ASC") + // .skip((i - 1) * BATCH_SIZE) + // .take(BATCH_SIZE) + // .getMany(); - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_EDUCATION_EMPRepo.find({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "EDUCATION_CODE", - "START_EDUCATION_YEAR", - "EDUCATION_YEAR", - "EDUCATION_NAME", - "INSTITUE", - ], - }); + await Promise.all( + profiles.map(async (_item) => { + const existingProfile = await this.HR_EDUCATION_EMPRepo.find({ + where: { CIT: _item.citizenId }, + select: ["CIT", "EDUCATION_CODE", "START_EDUCATION_YEAR", "EDUCATION_YEAR", "INSTITUE"], + }); - educations = await []; - await Promise.all( - existingProfile.map(async (item) => { - rowCount++; - const education = new ProfileEducation(); - const educationCode = await this.educationMisRepo.findOne({ - where: { EDUCATION_CODE: item.EDUCATION_CODE }, - }); + educations = await []; + await Promise.all( + existingProfile.map(async (item) => { + rowCount++; + const education = new ProfileEducation(); + const educationCode = await this.educationMisRepo.findOne({ + where: { EDUCATION_CODE: item.EDUCATION_CODE }, + }); - let startDate = item.START_EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) - : null_; - startDate = startDate ? new Date(startDate, 0, 1) : null_; + let startDate = item.START_EDUCATION_YEAR + ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) + : null_; + startDate = startDate ? new Date(startDate, 0, 1) : null_; - let endDate = item.EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.EDUCATION_YEAR) - : null_; - endDate = endDate ? new Date(endDate, 0, 1) : null_; + let endDate = item.EDUCATION_YEAR + ? Extension.ConvertToDateTime(item.EDUCATION_YEAR) + : null_; + endDate = endDate ? new Date(endDate, 0, 1) : null_; - education.profileEmployeeId = _item.id; - education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; - education.institute = item.INSTITUE; - education.startDate = startDate; - education.endDate = endDate; - education.createdUserId = request.user.sub; - education.createdFullName = request.user.name; - education.lastUpdateUserId = request.user.sub; - education.lastUpdateFullName = request.user.name; - educations.push(education); - }), - ); - await this.educationRepository.save(educations); - }), - ); - } + education.profileEmployeeId = _item.id; + education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; + education.institute = item.INSTITUE; + education.startDate = startDate; + education.endDate = endDate; + education.createdUserId = request.user.sub; + education.createdFullName = request.user.name; + education.lastUpdateUserId = request.user.sub; + education.lastUpdateFullName = request.user.name; + educations.push(education); + }), + ); + await this.educationRepository.save(educations); + }), + ); + // } console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); // await this.educationRepository.save(educations); return new HttpSuccess(); @@ -958,140 +956,144 @@ export class ImportDataController extends Controller { let rowCount = 0; let profileDatas: any = []; let null_: any = null; - const [_profiles, total] = await AppDataSource.getRepository(Profile) + const [profiles, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") - .select(["profile.id"]) + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + // .skip(0) + // .take(20) .getManyAndCount(); - for (var i = 1; i <= total / BATCH_SIZE; i++) { - const profiles = await AppDataSource.getRepository(Profile) - .createQueryBuilder("profile") - .orderBy("profile.citizenId", "ASC") - .skip((i - 1) * BATCH_SIZE) - .take(BATCH_SIZE) - .getMany(); - profileDatas = await []; - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_PERSONAL_OFFICER_ADDRESSRepo.findOne({ - where: { CIT: _item.citizenId }, + // for (var i = 1; i <= 2; i++) { + // const profiles = await AppDataSource.getRepository(Profile) + // .createQueryBuilder("profile") + // .orderBy("profile.citizenId", "ASC") + // .skip((i - 1) * 5) + // .take(5) + // .getMany(); + // profileDatas = await []; + await Promise.all( + profiles.map(async (_item) => { + const existingProfile = await this.HR_PERSONAL_OFFICER_ADDRESSRepo.findOne({ + where: { CIT: _item.citizenId }, + }); + + if (!existingProfile) { + return; + } + + rowCount++; + let provinceRegis_: any = null; + let districtRegis_: any = null; + let subDistrictRegis_: any = null; + let provinceCurr_: any = null; + let districtCurr_: any = null; + let subDistrictCurr_: any = null; + //registration address + if (existingProfile.PROVINCE_CODE) { + provinceRegis_ = await this.provincsRepo.findOne({ + where: { PROVINCE_CODE: existingProfile.PROVINCE_CODE }, }); - - if (!existingProfile) { - return; - } - - rowCount++; - let provinceRegis_: any = null; - let districtRegis_: any = null; - let subDistrictRegis_: any = null; - let provinceCurr_: any = null; - let districtCurr_: any = null; - let subDistrictCurr_: any = null; - //registration address - if (existingProfile.PROVINCE_CODE) { - provinceRegis_ = await this.provincsRepo.findOne({ - where: { PROVINCE_CODE: existingProfile.PROVINCE_CODE }, - }); - if (provinceRegis_) { - let provinceId = await this.provinceIdRepo.findOne({ - where: { - name: provinceRegis_.PROVINCE_NAME, - }, - }); - _item.registrationProvinceId = provinceId ? provinceId.id : null_; - } - } - if (existingProfile.AMPHUR_CODE && provinceRegis_) { - districtRegis_ = await this.amphurRepo.findOne({ + if (provinceRegis_) { + let provinceId = await this.provinceIdRepo.findOne({ where: { - AMPHUR_CODE: existingProfile.AMPHUR_CODE, - PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + name: provinceRegis_.PROVINCE_NAME, }, }); - if (districtRegis_) { - let districtId = await this.districtIdRepo.findOne({ - where: { - name: districtRegis_.AMPHUR_NAME, - }, - }); - _item.registrationDistrictId = districtId ? districtId.id : null_; - } + _item.registrationProvinceId = provinceId ? provinceId.id : null_; } - if (existingProfile.DISTRICT_CODE && districtRegis_ && provinceRegis_) { - subDistrictRegis_ = await this.subDistrictRepo.findOne({ + } + if (existingProfile.AMPHUR_CODE && provinceRegis_) { + districtRegis_ = await this.amphurRepo.findOne({ + where: { + AMPHUR_CODE: existingProfile.AMPHUR_CODE, + PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + }, + }); + if (districtRegis_) { + let districtId = await this.districtIdRepo.findOne({ where: { - DISTRICT_CODE: existingProfile.DISTRICT_CODE, - AMPHUR_CODE: districtRegis_.AMPHUR_CODE, - PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + name: districtRegis_.AMPHUR_NAME, }, }); - if (subDistrictRegis_) { - let subDistrictId = await this.subDistrictIdRepo.findOne({ - where: { - name: subDistrictRegis_.DISTRICT_NAME, - }, - }); - _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : null_; - } + _item.registrationDistrictId = districtId ? districtId.id : null_; } - //current address - if (existingProfile.CONTACT_PROVINCE_CODE) { - provinceCurr_ = await this.provincsRepo.findOne({ - where: { PROVINCE_CODE: existingProfile.CONTACT_PROVINCE_CODE }, - }); - if (provinceCurr_) { - let provinceId = await this.provinceIdRepo.findOne({ - where: { - name: provinceCurr_.PROVINCE_NAME, - }, - }); - _item.currentProvinceId = provinceId ? provinceId.id : null_; - } - } - if (existingProfile.CONTACT_AMPHUR_CODE && provinceCurr_) { - districtCurr_ = await this.amphurRepo.findOne({ + } + if (existingProfile.DISTRICT_CODE && districtRegis_ && provinceRegis_) { + subDistrictRegis_ = await this.subDistrictRepo.findOne({ + where: { + DISTRICT_CODE: existingProfile.DISTRICT_CODE, + AMPHUR_CODE: districtRegis_.AMPHUR_CODE, + PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + }, + }); + if (subDistrictRegis_) { + let subDistrictId = await this.subDistrictIdRepo.findOne({ where: { - AMPHUR_CODE: existingProfile.CONTACT_AMPHUR_CODE, - PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, + name: subDistrictRegis_.DISTRICT_NAME, }, }); - if (districtCurr_) { - let districtId = await this.districtIdRepo.findOne({ - where: { - name: districtCurr_.AMPHUR_NAME, - }, - }); - _item.currentDistrictId = districtId ? districtId.id : null_; - } + _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : null_; } - if (existingProfile.CONTACT_DISTRICT_CODE && districtCurr_ && provinceCurr_) { - subDistrictCurr_ = await this.subDistrictRepo.findOne({ + } + //current address + if (existingProfile.CONTACT_PROVINCE_CODE) { + provinceCurr_ = await this.provincsRepo.findOne({ + where: { PROVINCE_CODE: existingProfile.CONTACT_PROVINCE_CODE }, + }); + if (provinceCurr_) { + let provinceId = await this.provinceIdRepo.findOne({ where: { - DISTRICT_CODE: existingProfile.CONTACT_DISTRICT_CODE, - AMPHUR_CODE: districtCurr_.AMPHUR_CODE, - PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, + name: provinceCurr_.PROVINCE_NAME, }, }); - if (subDistrictCurr_) { - let subDistrictId = await this.subDistrictIdRepo.findOne({ - where: { - name: subDistrictCurr_.DISTRICT_NAME, - }, - }); - _item.currentSubDistrictId = subDistrictId ? subDistrictId.id : null_; - } + _item.currentProvinceId = provinceId ? provinceId.id : null_; } - _item.registrationAddress = existingProfile.H_NUMBER; - _item.registrationZipCode = existingProfile.ZIPCODE; - _item.currentAddress = existingProfile.CONTACT_H_NUMBER; - _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; - _item.lastUpdateUserId = request.user.sub; - _item.lastUpdateFullName = request.user.name; - profileDatas.push(_item); - }), - ); - await this.profileRepo.save(profileDatas); - } + } + if (existingProfile.CONTACT_AMPHUR_CODE && provinceCurr_) { + districtCurr_ = await this.amphurRepo.findOne({ + where: { + AMPHUR_CODE: existingProfile.CONTACT_AMPHUR_CODE, + PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, + }, + }); + if (districtCurr_) { + let districtId = await this.districtIdRepo.findOne({ + where: { + name: districtCurr_.AMPHUR_NAME, + }, + }); + _item.currentDistrictId = districtId ? districtId.id : null_; + } + } + if (existingProfile.CONTACT_DISTRICT_CODE && districtCurr_ && provinceCurr_) { + subDistrictCurr_ = await this.subDistrictRepo.findOne({ + where: { + DISTRICT_CODE: existingProfile.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, + }, + }); + _item.currentSubDistrictId = subDistrictId ? subDistrictId.id : null_; + } + } + _item.registrationAddress = existingProfile.H_NUMBER; + _item.registrationZipCode = existingProfile.ZIPCODE; + _item.currentAddress = existingProfile.CONTACT_H_NUMBER; + _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; + _item.lastUpdateUserId = request.user.sub; + _item.lastUpdateFullName = request.user.name; + // profileDatas.push(_item); + await this.profileRepo.save(_item); + }), + ); + // await this.profileRepo.save(profileDatas); + // } console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); return new HttpSuccess(); } @@ -1104,140 +1106,144 @@ export class ImportDataController extends Controller { let rowCount = 0; let profileDatas: any = []; let null_: any = null; - const [_profiles, total] = await AppDataSource.getRepository(ProfileEmployee) + const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) .createQueryBuilder("profile") - .select(["profile.id"]) + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + // .skip(0) + // .take(20) .getManyAndCount(); - for (var i = 1; i <= total / BATCH_SIZE; i++) { - const profiles = await AppDataSource.getRepository(ProfileEmployee) - .createQueryBuilder("profile") - .orderBy("profile.citizenId", "ASC") - .skip((i - 1) * BATCH_SIZE) - .take(BATCH_SIZE) - .getMany(); - profileDatas = await []; - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_PERSONAL_EMP_ADDRESSRepo.findOne({ - where: { CIT: _item.citizenId }, + // for (var i = 1; i <= total / BATCH_SIZE; i++) { + // const profiles = await AppDataSource.getRepository(ProfileEmployee) + // .createQueryBuilder("profile") + // .orderBy("profile.citizenId", "ASC") + // .skip((i - 1) * BATCH_SIZE) + // .take(BATCH_SIZE) + // .getMany(); + // profileDatas = await []; + await Promise.all( + profiles.map(async (_item) => { + const existingProfile = await this.HR_PERSONAL_EMP_ADDRESSRepo.findOne({ + where: { CIT: _item.citizenId }, + }); + + if (!existingProfile) { + return; + } + + rowCount++; + let provinceRegis_: any = null; + let districtRegis_: any = null; + let subDistrictRegis_: any = null; + let provinceCurr_: any = null; + let districtCurr_: any = null; + let subDistrictCurr_: any = null; + //registration address + if (existingProfile.PROVINCE_CODE) { + provinceRegis_ = await this.provincsRepo.findOne({ + where: { PROVINCE_CODE: existingProfile.PROVINCE_CODE }, }); - - if (!existingProfile) { - return; - } - - rowCount++; - let provinceRegis_: any = null; - let districtRegis_: any = null; - let subDistrictRegis_: any = null; - let provinceCurr_: any = null; - let districtCurr_: any = null; - let subDistrictCurr_: any = null; - //registration address - if (existingProfile.PROVINCE_CODE) { - provinceRegis_ = await this.provincsRepo.findOne({ - where: { PROVINCE_CODE: existingProfile.PROVINCE_CODE }, - }); - if (provinceRegis_) { - let provinceId = await this.provinceIdRepo.findOne({ - where: { - name: provinceRegis_.PROVINCE_NAME, - }, - }); - _item.registrationProvinceId = provinceId ? provinceId.id : null_; - } - } - if (existingProfile.AMPHUR_CODE) { - districtRegis_ = await this.amphurRepo.findOne({ + if (provinceRegis_) { + let provinceId = await this.provinceIdRepo.findOne({ where: { - AMPHUR_CODE: existingProfile.AMPHUR_CODE, - PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + name: provinceRegis_.PROVINCE_NAME, }, }); - if (districtRegis_) { - let districtId = await this.districtIdRepo.findOne({ - where: { - name: districtRegis_.AMPHUR_NAME, - }, - }); - _item.registrationDistrictId = districtId ? districtId.id : null_; - } + _item.registrationProvinceId = provinceId ? provinceId.id : null_; } - if (existingProfile.DISTRICT_CODE) { - subDistrictRegis_ = await this.subDistrictRepo.findOne({ + } + if (existingProfile.AMPHUR_CODE) { + districtRegis_ = await this.amphurRepo.findOne({ + where: { + AMPHUR_CODE: existingProfile.AMPHUR_CODE, + PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + }, + }); + if (districtRegis_) { + let districtId = await this.districtIdRepo.findOne({ where: { - DISTRICT_CODE: existingProfile.DISTRICT_CODE, - AMPHUR_CODE: districtRegis_.AMPHUR_CODE, - PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + name: districtRegis_.AMPHUR_NAME, }, }); - if (subDistrictRegis_) { - let subDistrictId = await this.subDistrictIdRepo.findOne({ - where: { - name: subDistrictRegis_.DISTRICT_NAME, - }, - }); - _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : null_; - } + _item.registrationDistrictId = districtId ? districtId.id : null_; } - //current address - if (existingProfile.CONTACT_PROVINCE_CODE) { - provinceCurr_ = await this.provincsRepo.findOne({ - where: { PROVINCE_CODE: existingProfile.CONTACT_PROVINCE_CODE }, - }); - if (provinceCurr_) { - let provinceId = await this.provinceIdRepo.findOne({ - where: { - name: provinceCurr_.PROVINCE_NAME, - }, - }); - _item.currentProvinceId = provinceId ? provinceId.id : null_; - } - } - if (existingProfile.CONTACT_AMPHUR_CODE) { - districtCurr_ = await this.amphurRepo.findOne({ + } + if (existingProfile.DISTRICT_CODE) { + subDistrictRegis_ = await this.subDistrictRepo.findOne({ + where: { + DISTRICT_CODE: existingProfile.DISTRICT_CODE, + AMPHUR_CODE: districtRegis_.AMPHUR_CODE, + PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + }, + }); + if (subDistrictRegis_) { + let subDistrictId = await this.subDistrictIdRepo.findOne({ where: { - AMPHUR_CODE: existingProfile.CONTACT_AMPHUR_CODE, - PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, + name: subDistrictRegis_.DISTRICT_NAME, }, }); - if (districtCurr_) { - let districtId = await this.districtIdRepo.findOne({ - where: { - name: districtCurr_.AMPHUR_NAME, - }, - }); - _item.currentDistrictId = districtId ? districtId.id : null_; - } + _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : null_; } - if (existingProfile.CONTACT_DISTRICT_CODE) { - subDistrictCurr_ = await this.subDistrictRepo.findOne({ + } + //current address + if (existingProfile.CONTACT_PROVINCE_CODE) { + provinceCurr_ = await this.provincsRepo.findOne({ + where: { PROVINCE_CODE: existingProfile.CONTACT_PROVINCE_CODE }, + }); + if (provinceCurr_) { + let provinceId = await this.provinceIdRepo.findOne({ where: { - DISTRICT_CODE: existingProfile.CONTACT_DISTRICT_CODE, - AMPHUR_CODE: districtCurr_.AMPHUR_CODE, - PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, + name: provinceCurr_.PROVINCE_NAME, }, }); - if (subDistrictCurr_) { - let subDistrictId = await this.subDistrictIdRepo.findOne({ - where: { - name: subDistrictCurr_.DISTRICT_NAME, - }, - }); - _item.currentSubDistrictId = subDistrictId ? subDistrictId.id : null_; - } + _item.currentProvinceId = provinceId ? provinceId.id : null_; } - _item.registrationAddress = existingProfile.H_NUMBER; - _item.registrationZipCode = existingProfile.ZIPCODE; - _item.currentAddress = existingProfile.CONTACT_H_NUMBER; - _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; - _item.lastUpdateUserId = request.user.sub; - _item.lastUpdateFullName = request.user.name; - profileDatas.push(_item); - }), - ); - await this.profileEmpRepo.save(profileDatas); - } + } + if (existingProfile.CONTACT_AMPHUR_CODE) { + districtCurr_ = await this.amphurRepo.findOne({ + where: { + AMPHUR_CODE: existingProfile.CONTACT_AMPHUR_CODE, + PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, + }, + }); + if (districtCurr_) { + let districtId = await this.districtIdRepo.findOne({ + where: { + name: districtCurr_.AMPHUR_NAME, + }, + }); + _item.currentDistrictId = districtId ? districtId.id : null_; + } + } + if (existingProfile.CONTACT_DISTRICT_CODE) { + subDistrictCurr_ = await this.subDistrictRepo.findOne({ + where: { + DISTRICT_CODE: existingProfile.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, + }, + }); + _item.currentSubDistrictId = subDistrictId ? subDistrictId.id : null_; + } + } + _item.registrationAddress = existingProfile.H_NUMBER; + _item.registrationZipCode = existingProfile.ZIPCODE; + _item.currentAddress = existingProfile.CONTACT_H_NUMBER; + _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; + _item.lastUpdateUserId = request.user.sub; + _item.lastUpdateFullName = request.user.name; + // profileDatas.push(_item); + await this.profileEmpRepo.save(_item); + }), + ); + // await this.profileEmpRepo.save(profileDatas); + // } console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); return new HttpSuccess(); } diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index b5539005..298d8d6b 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -81,7 +81,7 @@ export class PermissionController extends Controller { ...getDetail, roles: roleAttrData, }; - redisClient.set("role_" + request.user.sub, JSON.stringify(reply)); + redisClient.setex("role_" + request.user.sub, 86400, JSON.stringify(reply)); } return new HttpSuccess(reply); } @@ -129,7 +129,7 @@ export class PermissionController extends Controller { } const roleAttrData = await this.authRoleAttrRepo.find({ select: ["authSysId"], - where: { authRoleId: authRole.id }, + where: { authRoleId: authRole.id, attrIsList: true }, }); const getList = await this.authSysRepo.find({ @@ -150,8 +150,8 @@ export class PermissionController extends Controller { }; }) .sort((a, b) => a.order - b.order); - console.log(JSON.stringify(reply)); - redisClient.set("menu_" + request.user.sub, 30, JSON.stringify(reply)); + // console.log(JSON.stringify(reply)); + redisClient.setex("menu_" + request.user.sub, 86400, JSON.stringify(reply)); } return new HttpSuccess(reply);