searh report position
This commit is contained in:
parent
504d0ca1b3
commit
cf13eb6598
2 changed files with 174 additions and 130 deletions
|
|
@ -1509,7 +1509,6 @@ export class ImportDataController extends Controller {
|
|||
@Post("uploadProfileAddress-Officer")
|
||||
async UploadFileSQLAddress(@Request() request: { user: Record<string, any> }) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue