feat: 合并中国酒店的中英文名称

main
Lei OT 10 months ago
parent 61869bdbcd
commit 997e9adbeb

@ -6,11 +6,12 @@ const objectMapper = (input, keyMap) => _objectMapper(input || {}, keyMap, false
const infoDataMapper = (row) => {
const item = objectMapper(row, {
HotelId: 'hotel_id',
HotelName: 'hotel_name',
// LocaleName: 'hotel_name',
// HotelName: 'hotel_name',
LocaleName: 'hotel_name',
CountryCode: 'country_code',
CityId: 'city_id',
Address: 'address',
// Address: 'address',
AddressLocale: 'address',
Phone: 'phone',
Latitude: 'latitude',
Longitude: 'longitude',
@ -21,7 +22,7 @@ const infoDataMapper = (row) => {
HeroImg: 'hero_img',
SupplierType: 'supplier_type',
});
item.hotel_name = isEmpty(item.hotel_name) ? row.LocaleName : item.hotel_name;
// item.hotel_name = isEmpty(item.hotel_name) ? row.LocaleName : item.hotel_name;
const review = objectMapper(row.Review, {
Score: 'review_score',
ReviewCount: 'review_count',

@ -37,9 +37,9 @@ const Logs = models.requestLogsModel;
// Rooms.belongsTo(Hotelinfo, { targetKey: 'hotel_id', foreignKey: 'hotel_id', onDelete: 'NO ACTION', onUpdate: 'NO ACTION', });
Hotelinfo.belongsTo(HeytripIds, { as: 'aid', foreignKey: 'hotel_id', onDelete: 'NO ACTION', onUpdate: 'NO ACTION' });
Hotelinfo.hasMany(Hotelinfo2, { as: 'locale_info', sourceKey: 'hotel_id', foreignKey: 'hotel_id', onDelete: 'NO ACTION', onUpdate: 'NO ACTION' });
// Hotelinfo2.belongsTo(Hotelinfo, { as: 'locale_info2', targetKey: 'hotel_id', foreignKey: 'hotel_id', onDelete: 'NO ACTION', onUpdate: 'NO ACTION', });
Hotelinfo.hasMany(City, { as: 'city', sourceKey: 'city_id', foreignKey: 'id', onDelete: 'NO ACTION', onUpdate: 'NO ACTION', }); // 多语种, 所以实际是 hasMany , 用 hasOne 要指定 lgc= 1 或者2
Hotelinfo.hasMany(Country, { as: 'country', sourceKey: 'country_code', foreignKey: 'id', onDelete: 'NO ACTION', onUpdate: 'NO ACTION', }); // 多语种, 所以实际是 hasMany , 用 hasOne 要指定 lgc= 1 或者2
// Hotelinfo2.belongsTo(Hotelinfo, { targetKey: 'hotel_id', foreignKey: 'hotel_id', onDelete: 'NO ACTION', onUpdate: 'NO ACTION', });
class Heytrip {
/**
@ -87,7 +87,6 @@ class Heytrip {
{ model: City, as: 'city', attributes: ['id', 'name'], where: { lgc: 2 }, required: false, separate: true },
{ model: Country, as: 'country', attributes: ['id', 'name'], where: { lgc: 2 }, required: false, separate: true },
],
// include: [{ model: Hotelinfo2, as: 'h2', required: true }],
where: {
[Op.or]: keywordSearch,
// hotel_id: findIds,
@ -95,7 +94,7 @@ class Heytrip {
order: keywordOrder,
...options,
// raw: true,
nest: true,
// nest: true,
});
return { count, rows: rows.map((item) => item.dataValues) };
@ -235,25 +234,29 @@ class Heytrip {
return res;
};
chinaHotelsLgc2 = async (lgc) => {
// const [rows] = await Sequelize.query(
// `SELECT h.hotel_id
// FROM hotelinfo AS h
// LEFT JOIN hotelinfo2 AS h2 ON h.hotel_id =h2.hotel_id
// AND h2.lgc = ${lgc}
// WHERE h2.hi2_sn IS NULL LIMIT 10`
// );
const [rows] = await Sequelize.query(
`SELECT i.hotel_id ,IFNULL(h.hi2_sn, 0) info_exists
`SELECT i.hotel_id
-- FROM hotelinfo AS h
FROM heytrip_ids AS i
INNER JOIN hotelinfo AS h1 ON h1.hotel_id =i.hotel_id
LEFT JOIN hotelinfo2 AS h ON h.hotel_id = i.hotel_id
AND h.lgc = ${lgc}
WHERE h.hi2_sn IS NULL
AND update_flag != 99
AND h1.country_code ='CN'
-- AND i.hotel_id > 20000000
ORDER BY info_exists LIMIT 10`
LEFT JOIN hotelinfo2 AS h2 ON i.hotel_id =h2.hotel_id
AND h2.lgc = ${lgc}
WHERE h2.hi2_sn IS NULL
AND i.hotel_id > 20000000
LIMIT 10`
, { logging: false }
);
// const [rows] = await Sequelize.query(
// `SELECT i.hotel_id ,IFNULL(h.hi2_sn, 0) info_exists
// FROM heytrip_ids AS i
// INNER JOIN hotelinfo AS h1 ON h1.hotel_id =i.hotel_id
// LEFT JOIN hotelinfo2 AS h ON h.hotel_id = i.hotel_id
// AND h.lgc = ${lgc}
// WHERE h.hi2_sn IS NULL
// -- AND update_flag != 99
// -- AND h1.country_code ='CN'
// AND i.hotel_id > 20000000
// ORDER BY info_exists LIMIT 10`
// );
const res = await this.syncInitHotelLgcDetailsAction(rows, LGC_MAPPED[lgc]);
return res;
};
@ -316,8 +319,9 @@ class Heytrip {
return { next: !isEmpty(allIds), data: allIds };
}
const _BaseInfoExists = await Hotelinfo.findAll({ where: { hotel_id: allIds }, });
const updateIds = _BaseInfoExists.map((item) => `${item.hotel_id}`);
// console.log('updateIds', updateIds);
const _BaseInfoExistsMapped = _BaseInfoExists.reduce((ru, c) => ({...ru, [`${c.hotel_id}`]: c }), {});
const existsIds = _BaseInfoExists.map((item) => `${item.hotel_id}`);
// console.log('existsIds', existsIds);
const res = await AccommodationsDetails({
Language: lgcObj.locale,
@ -339,7 +343,26 @@ class Heytrip {
await HeytripIds.update({ update_flag: 99 }, { where: { hotel_id: offInfo }, ...sequelizeOptions });
}
const newInfo = insertData.info.filter((iitem) => !updateIds.includes(`${iitem.hotel_id}`));
const updateInfo = insertData.info.filter((iitem) => existsIds.includes(`${iitem.hotel_id}`));
if (!isEmpty(updateInfo)) {
await HeytripIds.update({ update_flag: 0 }, { where: { hotel_id: updateInfo.map((x) => x.hotel_id) }, ...sequelizeOptions });
for await (const updateRow of updateInfo) {
const _BaseName = _BaseInfoExistsMapped[`${updateRow.hotel_id}`].hotel_name;
if ((_BaseName || '').includes((updateRow.hotel_name || '').substring(0, 4))) {
continue;
}
const _BaseAddress = _BaseInfoExistsMapped[`${updateRow.hotel_id}`].address;
await Hotelinfo.update(
{
update_flag: 0,
hotel_name: lgcObj.lgc === 1 ? `${_BaseName}${updateRow.hotel_name}` : `${updateRow.hotel_name}${_BaseName}`,
address: lgcObj.lgc === 1 ? `${_BaseAddress}${updateRow.address}` : `${updateRow.address}${_BaseAddress}`,
},
{ where: { hotel_id: updateRow.hotel_id }, ...sequelizeOptions }
);
}
}
const newInfo = insertData.info.filter((iitem) => !existsIds.includes(`${iitem.hotel_id}`));
// console.log(
// 'newInfo',
// newInfo.map((xx) => xx.hotel_id)
@ -364,7 +387,7 @@ class Heytrip {
} catch (error) {
console.log(error);
return { next: false, data: allIds };
return { next: false, restart: true, data: allIds };
}
};

Loading…
Cancel
Save