From cf13eb65986f4a532d75e1d55a1a92f90258aa81 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 7 Mar 2025 11:15:50 +0700 Subject: [PATCH] searh report position --- src/controllers/ImportDataController.ts | 288 ++++++++++++++---------- src/controllers/ReportController.ts | 16 +- 2 files changed, 174 insertions(+), 130 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 5e431b43..1e457156 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -1509,7 +1509,6 @@ export class ImportDataController extends Controller { @Post("uploadProfileAddress-Officer") async UploadFileSQLAddress(@Request() request: { user: Record }) { let rowCount = 0; - let profileDatas: any = []; let null_: any = null; const [profiles, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") @@ -1518,143 +1517,190 @@ export class ImportDataController extends Controller { // .skip(0) // .take(20) .getManyAndCount(); - // 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 }, + const meta = { + createdUserId: request.user.sub, + createdFullName: request.user.name, + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + createdAt: new Date(), + lastUpdatedAt: new Date(), + }; + for (const _item of profiles) { + const existingProfile = await this.HR_PERSONAL_OFFICER_ADDRESSRepo.findOne({ + where: { CIT: _item.citizenId }, + }); + + if (!existingProfile) { + continue; + } + let PROVINCE_CODE = Number(existingProfile.PROVINCE_CODE).toString(); + let DISTRICT_CODE = Number(existingProfile.DISTRICT_CODE).toString(); + let AMPHUR_CODE = Number(existingProfile.AMPHUR_CODE).toString(); + let CONTACT_PROVINCE_CODE = Number(existingProfile.CONTACT_PROVINCE_CODE).toString(); + let CONTACT_DISTRICT_CODE = Number(existingProfile.CONTACT_DISTRICT_CODE).toString(); + let CONTACT_AMPHUR_CODE = Number(existingProfile.CONTACT_AMPHUR_CODE).toString(); + rowCount++; + //registration address + if (PROVINCE_CODE) { + let provinceRegis_ = await this.provincsRepo.findOne({ + where: { PROVINCE_CODE: 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({ + if (provinceId == null) { + provinceId = new Province(); + Object.assign(provinceId, { + ...meta, + name: provinceRegis_.PROVINCE_NAME, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.registrationProvinceId = provinceId ? provinceId.id : null_; + if (AMPHUR_CODE) { + let districtRegis_ = await this.amphurRepo.findOne({ where: { - name: districtRegis_.AMPHUR_NAME, + AMPHUR_CODE: AMPHUR_CODE, + PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, }, }); - _item.registrationDistrictId = districtId ? districtId.id : null_; + if (districtRegis_) { + let districtId = await this.districtIdRepo.findOne({ + where: { + name: districtRegis_.AMPHUR_NAME, + }, + }); + if (districtId == null) { + districtId = new District(); + Object.assign(districtId, { + ...meta, + name: districtRegis_.AMPHUR_NAME, + provinceId: provinceId.id, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.registrationDistrictId = districtId ? districtId.id : null_; + if (DISTRICT_CODE) { + let subDistrictRegis_ = await this.subDistrictRepo.findOne({ + where: { + DISTRICT_CODE: 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, + }, + }); + if (subDistrictId == null) { + subDistrictId = new SubDistrict(); + Object.assign(subDistrictId, { + ...meta, + name: subDistrictRegis_.DISTRICT_NAME, + zipCode: existingProfile.ZIPCODE, + districtId: districtId.id, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : null_; + } + } + } } } - if (existingProfile.DISTRICT_CODE && districtRegis_ && provinceRegis_) { - subDistrictRegis_ = await this.subDistrictRepo.findOne({ + } + //current address + if (CONTACT_PROVINCE_CODE) { + let provinceCurr_ = await this.provincsRepo.findOne({ + where: { PROVINCE_CODE: CONTACT_PROVINCE_CODE }, + }); + if (provinceCurr_) { + let provinceId = await this.provinceIdRepo.findOne({ where: { - DISTRICT_CODE: existingProfile.DISTRICT_CODE, - AMPHUR_CODE: districtRegis_.AMPHUR_CODE, - PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + name: provinceCurr_.PROVINCE_NAME, }, }); - if (subDistrictRegis_) { - let subDistrictId = await this.subDistrictIdRepo.findOne({ + if (provinceId == null) { + provinceId = new Province(); + Object.assign(provinceId, { + ...meta, + name: provinceCurr_.PROVINCE_NAME, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.currentProvinceId = provinceId ? provinceId.id : null_; + if (CONTACT_AMPHUR_CODE) { + let districtCurr_ = await this.amphurRepo.findOne({ where: { - name: subDistrictRegis_.DISTRICT_NAME, + AMPHUR_CODE: CONTACT_AMPHUR_CODE, + PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, }, }); - _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : null_; + if (districtCurr_) { + let districtId = await this.districtIdRepo.findOne({ + where: { + name: districtCurr_.AMPHUR_NAME, + }, + }); + if (districtId == null) { + districtId = new District(); + Object.assign(districtId, { + ...meta, + name: districtCurr_.AMPHUR_NAME, + provinceId: provinceId.id, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.currentDistrictId = districtId ? districtId.id : null_; + if (CONTACT_DISTRICT_CODE) { + let subDistrictCurr_ = await this.subDistrictRepo.findOne({ + where: { + DISTRICT_CODE: 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, + }, + }); + if (subDistrictId == null) { + subDistrictId = new SubDistrict(); + Object.assign(subDistrictId, { + ...meta, + name: subDistrictCurr_.DISTRICT_NAME, + zipCode: existingProfile.CONTACT_ZIPCODE, + districtId: districtId.id, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.currentSubDistrictId = subDistrictId ? subDistrictId.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({ - 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.createdUserId = request.user.sub; - _item.createdFullName = request.user.name; - _item.lastUpdateUserId = request.user.sub; - _item.lastUpdateFullName = request.user.name; - _item.createdAt = new Date(); - _item.lastUpdatedAt = new Date(); - // profileDatas.push(_item); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - await this.profileRepo.save(_item); - }), - ); - // await this.profileRepo.save(profileDatas); - // } - // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + } + _item.registrationAddress = existingProfile.H_NUMBER; + _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; + _item.createdAt = new Date(); + _item.lastUpdatedAt = new Date(); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileRepo.save(_item); + } return new HttpSuccess(); } diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 59748800..a34a9a1e 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -290,38 +290,36 @@ export class ReportController extends Controller { }) .andWhere(IsLeavecondition.join(" AND "), parameters) .andWhere( - posType != null && posType != "" ? "registryOfficer.posTypeName LIKE :posTypeName" : "1=1", + posType != null && posType != "" ? "registryOfficer.posTypeName = :posTypeName" : "1=1", { posTypeName: `%${posType}%`, }, ) .andWhere( - posLevel != null && posLevel != "" - ? "registryOfficer.posLevelName LIKE :posLevelName" - : "1=1", + posLevel != null && posLevel != "" ? "registryOfficer.posLevelName = :posLevelName" : "1=1", { posLevelName: `%${posLevel}%`, }, ) .andWhere( - position != null && position != "" ? "registryOfficer.position LIKE :position" : "1=1", + position != null && position != "" ? "registryOfficer.position = :position" : "1=1", { position: `%${position}%`, }, ) .andWhere( positionExecutive != null && positionExecutive != "" - ? "registryOfficer.posExecutiveName LIKE :posExecutiveName" + ? "registryOfficer.posExecutiveName = :posExecutiveName" : "1=1", { posExecutiveName: `%${positionExecutive}%`, }, ) - .andWhere(gender != null && gender != "" ? "registryOfficer.gender LIKE :gender" : "1=1", { + .andWhere(gender != null && gender != "" ? "registryOfficer.gender = :gender" : "1=1", { gender: `%${gender}%`, }) .andWhere( - status != null && status != "" ? "registryOfficer.relationship LIKE :relationship" : "1=1", + status != null && status != "" ? "registryOfficer.relationship = :relationship" : "1=1", { relationship: `%${status}%`, }, @@ -3537,7 +3535,7 @@ export class ReportController extends Controller { } } } - + return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); }