comment
This commit is contained in:
parent
a8bb884564
commit
84f14466c7
1 changed files with 434 additions and 434 deletions
|
|
@ -6366,447 +6366,447 @@ export class ImportDataController extends Controller {
|
|||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @summary Update importUpdate for provinces matching JSON
|
||||
// */
|
||||
// @Post("updateProvinceImportOld")
|
||||
// async updateProvinceImportOld() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/provinces.json");
|
||||
// const provinceJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// const Fuse = require("fuse.js");
|
||||
// const fuse = new Fuse(
|
||||
// provinceJson.map((x: any) => x.name_th),
|
||||
// {
|
||||
// includeScore: true,
|
||||
// threshold: 0.2, // ยิ่งต่ำยิ่งเข้มงวด
|
||||
// },
|
||||
// );
|
||||
// const provinces = await this.provinceIdRepo.find({ where: { importUpdate: IsNull() } });
|
||||
// for (const prov of provinces) {
|
||||
// console.log("11");
|
||||
// const result = fuse.search(prov.name);
|
||||
// const repoProvince = AppDataSource.getRepository(ProvinceMaster);
|
||||
// console.log("1221");
|
||||
// if (result.length > 0) {
|
||||
// let foundItem = result[0];
|
||||
// if (result.length > 1) {
|
||||
// foundItem = result.filter((x: any) => x.score == 0)[0];
|
||||
// if (foundItem == null) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// const province = await repoProvince.findOne({
|
||||
// where: { name_th: foundItem.item },
|
||||
// });
|
||||
// if (province == null) {
|
||||
// console.log(foundItem.item);
|
||||
// num += 1;
|
||||
// continue;
|
||||
// }
|
||||
// console.log("1441");
|
||||
// prov.importUpdate = 1;
|
||||
// prov.refId = province.id;
|
||||
// prov.name = province.name_th;
|
||||
// await this.provinceIdRepo.save(prov);
|
||||
// } else {
|
||||
// console.log("qqqqq");
|
||||
// console.log(prov.name);
|
||||
// console.log(result);
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// console.log("not found province count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
// /**
|
||||
// * @summary Update importUpdate for provinces matching JSON
|
||||
// */
|
||||
// @Post("updateProvinceImportOld")
|
||||
// async updateProvinceImportOld() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/provinces.json");
|
||||
// const provinceJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// const Fuse = require("fuse.js");
|
||||
// const fuse = new Fuse(
|
||||
// provinceJson.map((x: any) => x.name_th),
|
||||
// {
|
||||
// includeScore: true,
|
||||
// threshold: 0.2, // ยิ่งต่ำยิ่งเข้มงวด
|
||||
// },
|
||||
// );
|
||||
// const provinces = await this.provinceIdRepo.find({ where: { importUpdate: IsNull() } });
|
||||
// for (const prov of provinces) {
|
||||
// console.log("11");
|
||||
// const result = fuse.search(prov.name);
|
||||
// const repoProvince = AppDataSource.getRepository(ProvinceMaster);
|
||||
// console.log("1221");
|
||||
// if (result.length > 0) {
|
||||
// let foundItem = result[0];
|
||||
// if (result.length > 1) {
|
||||
// foundItem = result.filter((x: any) => x.score == 0)[0];
|
||||
// if (foundItem == null) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// const province = await repoProvince.findOne({
|
||||
// where: { name_th: foundItem.item },
|
||||
// });
|
||||
// if (province == null) {
|
||||
// console.log(foundItem.item);
|
||||
// num += 1;
|
||||
// continue;
|
||||
// }
|
||||
// console.log("1441");
|
||||
// prov.importUpdate = 1;
|
||||
// prov.refId = province.id;
|
||||
// prov.name = province.name_th;
|
||||
// await this.provinceIdRepo.save(prov);
|
||||
// } else {
|
||||
// console.log("qqqqq");
|
||||
// console.log(prov.name);
|
||||
// console.log(result);
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// console.log("not found province count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @summary Update importUpdate for districts matching JSON
|
||||
// */
|
||||
// @Post("updateDistrictImportOld")
|
||||
// async updateDistrictImportOld() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/tambons.json");
|
||||
// const districtJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// const Fuse = require("fuse.js");
|
||||
// const districts = await this.districtIdRepo.find({
|
||||
// relations: ["province"],
|
||||
// where: { province: { refId: Not(IsNull()) }, importUpdate: IsNull() },
|
||||
// });
|
||||
// for (const prov of districts) {
|
||||
// const fuse = new Fuse(
|
||||
// districtJson
|
||||
// .filter((x: any) => x.province_id === prov.province?.refId)
|
||||
// .map((x: any) => x.name_th),
|
||||
// {
|
||||
// includeScore: true,
|
||||
// threshold: 0.2, // ยิ่งต่ำยิ่งเข้มงวด
|
||||
// },
|
||||
// );
|
||||
// const result = fuse.search(prov.name);
|
||||
// const repoDistrict = AppDataSource.getRepository(DistrictMaster);
|
||||
// if (result.length > 0) {
|
||||
// let foundItem = result[0];
|
||||
// if (result.length > 1) {
|
||||
// foundItem = result.filter((x: any) => x.score == 0)[0];
|
||||
// if (foundItem == null) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// const district = await repoDistrict.findOne({
|
||||
// where: { name_th: foundItem.item, province_id: prov.province?.refId },
|
||||
// });
|
||||
// if (district == null) {
|
||||
// num += 1;
|
||||
// continue;
|
||||
// }
|
||||
// prov.importUpdate = 1;
|
||||
// prov.refId = district.id;
|
||||
// prov.name = district.name_th;
|
||||
// await this.districtIdRepo.save(prov);
|
||||
// } else {
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// console.log("not found district count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
// /**
|
||||
// * @summary Update importUpdate for districts matching JSON
|
||||
// */
|
||||
// @Post("updateDistrictImportOld")
|
||||
// async updateDistrictImportOld() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/tambons.json");
|
||||
// const districtJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// const Fuse = require("fuse.js");
|
||||
// const districts = await this.districtIdRepo.find({
|
||||
// relations: ["province"],
|
||||
// where: { province: { refId: Not(IsNull()) }, importUpdate: IsNull() },
|
||||
// });
|
||||
// for (const prov of districts) {
|
||||
// const fuse = new Fuse(
|
||||
// districtJson
|
||||
// .filter((x: any) => x.province_id === prov.province?.refId)
|
||||
// .map((x: any) => x.name_th),
|
||||
// {
|
||||
// includeScore: true,
|
||||
// threshold: 0.2, // ยิ่งต่ำยิ่งเข้มงวด
|
||||
// },
|
||||
// );
|
||||
// const result = fuse.search(prov.name);
|
||||
// const repoDistrict = AppDataSource.getRepository(DistrictMaster);
|
||||
// if (result.length > 0) {
|
||||
// let foundItem = result[0];
|
||||
// if (result.length > 1) {
|
||||
// foundItem = result.filter((x: any) => x.score == 0)[0];
|
||||
// if (foundItem == null) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// const district = await repoDistrict.findOne({
|
||||
// where: { name_th: foundItem.item, province_id: prov.province?.refId },
|
||||
// });
|
||||
// if (district == null) {
|
||||
// num += 1;
|
||||
// continue;
|
||||
// }
|
||||
// prov.importUpdate = 1;
|
||||
// prov.refId = district.id;
|
||||
// prov.name = district.name_th;
|
||||
// await this.districtIdRepo.save(prov);
|
||||
// } else {
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// console.log("not found district count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @summary Update importUpdate for subdistricts matching JSON
|
||||
// */
|
||||
// @Post("updateSubDistrictImportOld")
|
||||
// async updateSubDistrictImportOld() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/amphures.json");
|
||||
// const subDistrictJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// const Fuse = require("fuse.js");
|
||||
// const subDistricts = await this.subDistrictIdRepo.find({
|
||||
// relations: ["district"],
|
||||
// where: { district: { refId: Not(IsNull()) }, importUpdate: IsNull() },
|
||||
// });
|
||||
// for (const prov of subDistricts) {
|
||||
// const fuse = new Fuse(
|
||||
// subDistrictJson
|
||||
// .filter((x: any) => x.district_id === prov.district?.refId)
|
||||
// .map((x: any) => x.name_th),
|
||||
// {
|
||||
// includeScore: true,
|
||||
// threshold: 0.2, // ยิ่งต่ำยิ่งเข้มงวด
|
||||
// },
|
||||
// );
|
||||
// const result = fuse.search(prov.name);
|
||||
// const repoSubDistrict = AppDataSource.getRepository(SubDistrictMaster);
|
||||
// if (result.length > 0) {
|
||||
// let foundItem = result[0];
|
||||
// if (result.length > 1) {
|
||||
// foundItem = result.filter((x: any) => x.score == 0)[0];
|
||||
// if (foundItem == null) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// const subdistrict = await repoSubDistrict.findOne({
|
||||
// where: { name_th: foundItem.item, district_id: prov.district?.refId },
|
||||
// });
|
||||
// if (subdistrict == null) {
|
||||
// num += 1;
|
||||
// continue;
|
||||
// }
|
||||
// prov.importUpdate = 1;
|
||||
// prov.refId = subdistrict.id;
|
||||
// prov.name = subdistrict.name_th;
|
||||
// prov.zipCode = subdistrict.zip_code.toString();
|
||||
// await this.subDistrictIdRepo.save(prov);
|
||||
// } else {
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// console.log("not found subdistrict count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
// /**
|
||||
// * @summary Update importUpdate for subdistricts matching JSON
|
||||
// */
|
||||
// @Post("updateSubDistrictImportOld")
|
||||
// async updateSubDistrictImportOld() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/amphures.json");
|
||||
// const subDistrictJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// const Fuse = require("fuse.js");
|
||||
// const subDistricts = await this.subDistrictIdRepo.find({
|
||||
// relations: ["district"],
|
||||
// where: { district: { refId: Not(IsNull()) }, importUpdate: IsNull() },
|
||||
// });
|
||||
// for (const prov of subDistricts) {
|
||||
// const fuse = new Fuse(
|
||||
// subDistrictJson
|
||||
// .filter((x: any) => x.district_id === prov.district?.refId)
|
||||
// .map((x: any) => x.name_th),
|
||||
// {
|
||||
// includeScore: true,
|
||||
// threshold: 0.2, // ยิ่งต่ำยิ่งเข้มงวด
|
||||
// },
|
||||
// );
|
||||
// const result = fuse.search(prov.name);
|
||||
// const repoSubDistrict = AppDataSource.getRepository(SubDistrictMaster);
|
||||
// if (result.length > 0) {
|
||||
// let foundItem = result[0];
|
||||
// if (result.length > 1) {
|
||||
// foundItem = result.filter((x: any) => x.score == 0)[0];
|
||||
// if (foundItem == null) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// const subdistrict = await repoSubDistrict.findOne({
|
||||
// where: { name_th: foundItem.item, district_id: prov.district?.refId },
|
||||
// });
|
||||
// if (subdistrict == null) {
|
||||
// num += 1;
|
||||
// continue;
|
||||
// }
|
||||
// prov.importUpdate = 1;
|
||||
// prov.refId = subdistrict.id;
|
||||
// prov.name = subdistrict.name_th;
|
||||
// prov.zipCode = subdistrict.zip_code.toString();
|
||||
// await this.subDistrictIdRepo.save(prov);
|
||||
// } else {
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// console.log("not found subdistrict count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @summary Update importUpdate for provinces matching JSON
|
||||
// */
|
||||
// @Post("updateProvinceImportFlag")
|
||||
// async updateProvinceImportFlag() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/provinces.json");
|
||||
// const provinceJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// for (const province of provinceJson) {
|
||||
// const dbProvince = await this.provinceIdRepo.findOne({
|
||||
// where: {
|
||||
// name: province.name_th,
|
||||
// importUpdate: IsNull(),
|
||||
// },
|
||||
// });
|
||||
// if (dbProvince) {
|
||||
// dbProvince.importUpdate = 1;
|
||||
// dbProvince.refId = province.id;
|
||||
// await this.provinceIdRepo.save(dbProvince);
|
||||
// } else {
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// console.log("not found province count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
// /**
|
||||
// * @summary Update importUpdate for provinces matching JSON
|
||||
// */
|
||||
// @Post("updateProvinceImportFlag")
|
||||
// async updateProvinceImportFlag() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/provinces.json");
|
||||
// const provinceJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// for (const province of provinceJson) {
|
||||
// const dbProvince = await this.provinceIdRepo.findOne({
|
||||
// where: {
|
||||
// name: province.name_th,
|
||||
// importUpdate: IsNull(),
|
||||
// },
|
||||
// });
|
||||
// if (dbProvince) {
|
||||
// dbProvince.importUpdate = 1;
|
||||
// dbProvince.refId = province.id;
|
||||
// await this.provinceIdRepo.save(dbProvince);
|
||||
// } else {
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// console.log("not found province count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @summary Update importUpdate for districts matching JSON
|
||||
// */
|
||||
// @Post("updateDistrictImportFlag")
|
||||
// async updateDistrictImportFlag() {
|
||||
// const meta = {
|
||||
// createdUserId: "",
|
||||
// createdFullName: "system",
|
||||
// lastUpdateUserId: "",
|
||||
// lastUpdateFullName: "system",
|
||||
// createdAt: new Date(),
|
||||
// lastUpdatedAt: new Date(),
|
||||
// };
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/tambons.json");
|
||||
// const tambonJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// for (const tambon of tambonJson) {
|
||||
// const dbDistrict = await this.districtIdRepo.findOne({
|
||||
// where: {
|
||||
// name: tambon.name_th,
|
||||
// province: { refId: Not(tambon.province_id) },
|
||||
// importUpdate: IsNull(),
|
||||
// },
|
||||
// });
|
||||
// if (dbDistrict) {
|
||||
// const dbProvince = await this.provinceIdRepo.findOne({
|
||||
// where: {
|
||||
// refId: tambon.province_id,
|
||||
// importUpdate: Not(IsNull()),
|
||||
// },
|
||||
// });
|
||||
// if (dbProvince) {
|
||||
// const checkOld = await this.districtIdRepo.findOne({
|
||||
// where: {
|
||||
// name: tambon.name_th,
|
||||
// provinceId: dbProvince.id,
|
||||
// },
|
||||
// });
|
||||
// if (!checkOld) {
|
||||
// let districtId = new District();
|
||||
// Object.assign(districtId, {
|
||||
// ...meta,
|
||||
// name: tambon.name_th,
|
||||
// provinceId: dbProvince.id,
|
||||
// importUpdate: 2,
|
||||
// refId: tambon.id,
|
||||
// });
|
||||
// await this.districtIdRepo.save(districtId);
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// console.log("not found province count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
// /**
|
||||
// * @summary Update importUpdate for districts matching JSON
|
||||
// */
|
||||
// @Post("updateDistrictImportFlag")
|
||||
// async updateDistrictImportFlag() {
|
||||
// const meta = {
|
||||
// createdUserId: "",
|
||||
// createdFullName: "system",
|
||||
// lastUpdateUserId: "",
|
||||
// lastUpdateFullName: "system",
|
||||
// createdAt: new Date(),
|
||||
// lastUpdatedAt: new Date(),
|
||||
// };
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/tambons.json");
|
||||
// const tambonJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// for (const tambon of tambonJson) {
|
||||
// const dbDistrict = await this.districtIdRepo.findOne({
|
||||
// where: {
|
||||
// name: tambon.name_th,
|
||||
// province: { refId: Not(tambon.province_id) },
|
||||
// importUpdate: IsNull(),
|
||||
// },
|
||||
// });
|
||||
// if (dbDistrict) {
|
||||
// const dbProvince = await this.provinceIdRepo.findOne({
|
||||
// where: {
|
||||
// refId: tambon.province_id,
|
||||
// importUpdate: Not(IsNull()),
|
||||
// },
|
||||
// });
|
||||
// if (dbProvince) {
|
||||
// const checkOld = await this.districtIdRepo.findOne({
|
||||
// where: {
|
||||
// name: tambon.name_th,
|
||||
// provinceId: dbProvince.id,
|
||||
// },
|
||||
// });
|
||||
// if (!checkOld) {
|
||||
// let districtId = new District();
|
||||
// Object.assign(districtId, {
|
||||
// ...meta,
|
||||
// name: tambon.name_th,
|
||||
// provinceId: dbProvince.id,
|
||||
// importUpdate: 2,
|
||||
// refId: tambon.id,
|
||||
// });
|
||||
// await this.districtIdRepo.save(districtId);
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// console.log("not found province count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @summary Update importUpdate for subdistricts matching JSON
|
||||
// */
|
||||
// @Post("updateSubDistrictImportFlag")
|
||||
// async updateSubDistrictImportFlag() {
|
||||
// const meta = {
|
||||
// createdUserId: "",
|
||||
// createdFullName: "system",
|
||||
// lastUpdateUserId: "",
|
||||
// lastUpdateFullName: "system",
|
||||
// createdAt: new Date(),
|
||||
// lastUpdatedAt: new Date(),
|
||||
// };
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/amphures.json");
|
||||
// const amphureJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// for (const amphure of amphureJson) {
|
||||
// const dbSubDistrict = await this.subDistrictIdRepo.findOne({
|
||||
// where: {
|
||||
// name: amphure.name_th,
|
||||
// district: { refId: Not(amphure.district_id) },
|
||||
// importUpdate: IsNull(),
|
||||
// },
|
||||
// });
|
||||
// if (dbSubDistrict) {
|
||||
// const dbDistrict = await this.districtIdRepo.findOne({
|
||||
// where: {
|
||||
// refId: amphure.district_id,
|
||||
// importUpdate: Not(IsNull()),
|
||||
// },
|
||||
// });
|
||||
// if (dbDistrict) {
|
||||
// const checkOld = await this.subDistrictIdRepo.findOne({
|
||||
// where: {
|
||||
// name: amphure.name_th,
|
||||
// districtId: dbDistrict.id,
|
||||
// },
|
||||
// });
|
||||
// if (!checkOld) {
|
||||
// let districtId = new District();
|
||||
// Object.assign(districtId, {
|
||||
// ...meta,
|
||||
// name: amphure.name_th,
|
||||
// districtId: dbDistrict.id,
|
||||
// zipCode: amphure.zip_code,
|
||||
// importUpdate: 2,
|
||||
// refId: amphure.id,
|
||||
// });
|
||||
// await this.subDistrictIdRepo.save(districtId);
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// console.log("not found province count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
// /**
|
||||
// * @summary ตรวจสอบ district ใน profile ว่าตรงกับ tambons.json หรือไม่
|
||||
// */
|
||||
// @Post("checkProfileDistrictMismatch")
|
||||
// async checkProfileDistrictMismatch() {
|
||||
// const mismatches = [];
|
||||
// const profiles = await this.profileRepo.find({
|
||||
// relations: ["registrationProvince", "registrationDistrict", "registrationSubDistrict"],
|
||||
// where: {
|
||||
// registrationProvince: Not(IsNull()),
|
||||
// },
|
||||
// });
|
||||
// for (const profile of profiles) {
|
||||
// console.log("profile count:", profiles.indexOf(profile) + 1);
|
||||
// console.log("mismatches count:", mismatches.length);
|
||||
// // if (mismatches.length >= 10) {
|
||||
// // break;
|
||||
// // }
|
||||
// const repoProvince = AppDataSource.getRepository(ProvinceMaster);
|
||||
// const repoDistrict = AppDataSource.getRepository(DistrictMaster);
|
||||
// const repoSubDistrict = AppDataSource.getRepository(SubDistrictMaster);
|
||||
// /**
|
||||
// * @summary Update importUpdate for subdistricts matching JSON
|
||||
// */
|
||||
// @Post("updateSubDistrictImportFlag")
|
||||
// async updateSubDistrictImportFlag() {
|
||||
// const meta = {
|
||||
// createdUserId: "",
|
||||
// createdFullName: "system",
|
||||
// lastUpdateUserId: "",
|
||||
// lastUpdateFullName: "system",
|
||||
// createdAt: new Date(),
|
||||
// lastUpdatedAt: new Date(),
|
||||
// };
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/amphures.json");
|
||||
// const amphureJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// let num = 0;
|
||||
// for (const amphure of amphureJson) {
|
||||
// const dbSubDistrict = await this.subDistrictIdRepo.findOne({
|
||||
// where: {
|
||||
// name: amphure.name_th,
|
||||
// district: { refId: Not(amphure.district_id) },
|
||||
// importUpdate: IsNull(),
|
||||
// },
|
||||
// });
|
||||
// if (dbSubDistrict) {
|
||||
// const dbDistrict = await this.districtIdRepo.findOne({
|
||||
// where: {
|
||||
// refId: amphure.district_id,
|
||||
// importUpdate: Not(IsNull()),
|
||||
// },
|
||||
// });
|
||||
// if (dbDistrict) {
|
||||
// const checkOld = await this.subDistrictIdRepo.findOne({
|
||||
// where: {
|
||||
// name: amphure.name_th,
|
||||
// districtId: dbDistrict.id,
|
||||
// },
|
||||
// });
|
||||
// if (!checkOld) {
|
||||
// let districtId = new District();
|
||||
// Object.assign(districtId, {
|
||||
// ...meta,
|
||||
// name: amphure.name_th,
|
||||
// districtId: dbDistrict.id,
|
||||
// zipCode: amphure.zip_code,
|
||||
// importUpdate: 2,
|
||||
// refId: amphure.id,
|
||||
// });
|
||||
// await this.subDistrictIdRepo.save(districtId);
|
||||
// num += 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// console.log("not found province count:", num);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
// /**
|
||||
// * @summary ตรวจสอบ district ใน profile ว่าตรงกับ tambons.json หรือไม่
|
||||
// */
|
||||
// @Post("checkProfileDistrictMismatch")
|
||||
// async checkProfileDistrictMismatch() {
|
||||
// const mismatches = [];
|
||||
// const profiles = await this.profileRepo.find({
|
||||
// relations: ["registrationProvince", "registrationDistrict", "registrationSubDistrict"],
|
||||
// where: {
|
||||
// registrationProvince: Not(IsNull()),
|
||||
// },
|
||||
// });
|
||||
// for (const profile of profiles) {
|
||||
// console.log("profile count:", profiles.indexOf(profile) + 1);
|
||||
// console.log("mismatches count:", mismatches.length);
|
||||
// // if (mismatches.length >= 10) {
|
||||
// // break;
|
||||
// // }
|
||||
// const repoProvince = AppDataSource.getRepository(ProvinceMaster);
|
||||
// const repoDistrict = AppDataSource.getRepository(DistrictMaster);
|
||||
// const repoSubDistrict = AppDataSource.getRepository(SubDistrictMaster);
|
||||
|
||||
// const registrationProvince = profile.registrationProvince?.name;
|
||||
// const registrationDistrict = profile.registrationDistrict?.name;
|
||||
// const registrationSubDistrict = profile.registrationSubDistrict?.name;
|
||||
// const registrationProvince = profile.registrationProvince?.name;
|
||||
// const registrationDistrict = profile.registrationDistrict?.name;
|
||||
// const registrationSubDistrict = profile.registrationSubDistrict?.name;
|
||||
|
||||
// const province = await repoProvince.findOne({
|
||||
// where: { name_th: registrationProvince },
|
||||
// });
|
||||
// if (province == null) {
|
||||
// mismatches.push({ profileId: profile.id });
|
||||
// continue;
|
||||
// }
|
||||
// const district = await repoDistrict.findOne({
|
||||
// where: { name_th: registrationDistrict, province_id: province.id },
|
||||
// });
|
||||
// if (district == null) {
|
||||
// mismatches.push({ profileId: profile.id });
|
||||
// continue;
|
||||
// }
|
||||
// const subdistrict = await repoSubDistrict.findOne({
|
||||
// where: { name_th: registrationSubDistrict, district_id: district.id },
|
||||
// });
|
||||
// if (subdistrict == null) {
|
||||
// mismatches.push({ profileId: profile.id });
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// return mismatches.map((x) => x.profileId);
|
||||
// }
|
||||
// const province = await repoProvince.findOne({
|
||||
// where: { name_th: registrationProvince },
|
||||
// });
|
||||
// if (province == null) {
|
||||
// mismatches.push({ profileId: profile.id });
|
||||
// continue;
|
||||
// }
|
||||
// const district = await repoDistrict.findOne({
|
||||
// where: { name_th: registrationDistrict, province_id: province.id },
|
||||
// });
|
||||
// if (district == null) {
|
||||
// mismatches.push({ profileId: profile.id });
|
||||
// continue;
|
||||
// }
|
||||
// const subdistrict = await repoSubDistrict.findOne({
|
||||
// where: { name_th: registrationSubDistrict, district_id: district.id },
|
||||
// });
|
||||
// if (subdistrict == null) {
|
||||
// mismatches.push({ profileId: profile.id });
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// return mismatches.map((x) => x.profileId);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @summary Import provinces.json into ProvinceMaster table
|
||||
// */
|
||||
// @Post("importProvinceMaster")
|
||||
// async importProvinceMaster() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/provinces.json");
|
||||
// const provinceJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// const repo = AppDataSource.getRepository(ProvinceMaster);
|
||||
// let imported = [];
|
||||
// for (const prov of provinceJson) {
|
||||
// const newProv = repo.create({
|
||||
// id: prov.id,
|
||||
// name_th: prov.name_th,
|
||||
// name_en: prov.name_en,
|
||||
// geography_id: prov.geography_id,
|
||||
// created_at: prov.created_at,
|
||||
// updated_at: prov.updated_at,
|
||||
// });
|
||||
// await repo.save(newProv);
|
||||
// imported.push(newProv);
|
||||
// }
|
||||
// return imported;
|
||||
// }
|
||||
// /**
|
||||
// * @summary Import provinces.json into ProvinceMaster table
|
||||
// */
|
||||
// @Post("importProvinceMaster")
|
||||
// async importProvinceMaster() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/provinces.json");
|
||||
// const provinceJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// const repo = AppDataSource.getRepository(ProvinceMaster);
|
||||
// let imported = [];
|
||||
// for (const prov of provinceJson) {
|
||||
// const newProv = repo.create({
|
||||
// id: prov.id,
|
||||
// name_th: prov.name_th,
|
||||
// name_en: prov.name_en,
|
||||
// geography_id: prov.geography_id,
|
||||
// created_at: prov.created_at,
|
||||
// updated_at: prov.updated_at,
|
||||
// });
|
||||
// await repo.save(newProv);
|
||||
// imported.push(newProv);
|
||||
// }
|
||||
// return imported;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @summary Import tambons.json into DistrictMaster table
|
||||
// */
|
||||
// @Post("importDistrictMaster")
|
||||
// async importDistrictMaster() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/tambons.json");
|
||||
// const tambonJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// const repo = AppDataSource.getRepository(DistrictMaster);
|
||||
// let imported = [];
|
||||
// for (const tambon of tambonJson) {
|
||||
// const newSub = repo.create({
|
||||
// id: tambon.id,
|
||||
// name_th: tambon.name_th,
|
||||
// name_en: tambon.name_en,
|
||||
// province_id: tambon.province_id,
|
||||
// created_at: tambon.created_at,
|
||||
// updated_at: tambon.updated_at,
|
||||
// });
|
||||
// await repo.save(newSub);
|
||||
// imported.push(newSub);
|
||||
// }
|
||||
// return imported;
|
||||
// }
|
||||
// /**
|
||||
// * @summary Import tambons.json into DistrictMaster table
|
||||
// */
|
||||
// @Post("importDistrictMaster")
|
||||
// async importDistrictMaster() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/tambons.json");
|
||||
// const tambonJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// const repo = AppDataSource.getRepository(DistrictMaster);
|
||||
// let imported = [];
|
||||
// for (const tambon of tambonJson) {
|
||||
// const newSub = repo.create({
|
||||
// id: tambon.id,
|
||||
// name_th: tambon.name_th,
|
||||
// name_en: tambon.name_en,
|
||||
// province_id: tambon.province_id,
|
||||
// created_at: tambon.created_at,
|
||||
// updated_at: tambon.updated_at,
|
||||
// });
|
||||
// await repo.save(newSub);
|
||||
// imported.push(newSub);
|
||||
// }
|
||||
// return imported;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @summary Import amphures.json into SubDistrictMaster table
|
||||
// */
|
||||
// @Post("importSubDistrictMaster")
|
||||
// async importSubDistrictMaster() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/amphures.json");
|
||||
// const amphureJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// const repo = AppDataSource.getRepository(SubDistrictMaster);
|
||||
// // Prepare all entities first
|
||||
// const entities = amphureJson.map((amphure: any) =>
|
||||
// repo.create({
|
||||
// id: amphure.id,
|
||||
// zip_code: amphure.zip_code,
|
||||
// name_th: amphure.name_th,
|
||||
// name_en: amphure.name_en,
|
||||
// district_id: amphure.district_id,
|
||||
// lat: amphure.lat,
|
||||
// long: amphure.long,
|
||||
// created_at: amphure.created_at,
|
||||
// updated_at: amphure.updated_at,
|
||||
// }),
|
||||
// );
|
||||
// // Bulk insert for performance
|
||||
// await repo.save(entities);
|
||||
// return entities;
|
||||
// }
|
||||
// }
|
||||
// /**
|
||||
// * @summary Import amphures.json into SubDistrictMaster table
|
||||
// */
|
||||
// @Post("importSubDistrictMaster")
|
||||
// async importSubDistrictMaster() {
|
||||
// const fs = require("fs");
|
||||
// const path = require("path");
|
||||
// const filePath = path.join(__dirname, "../data/amphures.json");
|
||||
// const amphureJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
// const repo = AppDataSource.getRepository(SubDistrictMaster);
|
||||
// // Prepare all entities first
|
||||
// const entities = amphureJson.map((amphure: any) =>
|
||||
// repo.create({
|
||||
// id: amphure.id,
|
||||
// zip_code: amphure.zip_code,
|
||||
// name_th: amphure.name_th,
|
||||
// name_en: amphure.name_en,
|
||||
// district_id: amphure.district_id,
|
||||
// lat: amphure.lat,
|
||||
// long: amphure.long,
|
||||
// created_at: amphure.created_at,
|
||||
// updated_at: amphure.updated_at,
|
||||
// }),
|
||||
// );
|
||||
// // Bulk insert for performance
|
||||
// await repo.save(entities);
|
||||
// return entities;
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue