Додан пошук територій за назвою вулиці
This commit is contained in:
@@ -11,7 +11,7 @@ cron.schedule("30 22 * * *", () => {
|
||||
});
|
||||
|
||||
// 2. Перевірка стендів без графіку щосуботи о 18:00
|
||||
cron.schedule("0 18 * * 6", async () => {
|
||||
cron.schedule("0 8 * * 6", async () => {
|
||||
console.log(`[${new Date().toLocaleString()}] Запуск перевірки стендів без графіку...`);
|
||||
try {
|
||||
await Stand.check_add();
|
||||
|
||||
@@ -33,7 +33,8 @@ class Stands {
|
||||
return;
|
||||
}
|
||||
|
||||
const dateNow = Date.now();
|
||||
const ONE_DAY = 24 * 60 * 60 * 1000;
|
||||
const dateNow = Date.now() + 7 * ONE_DAY;
|
||||
|
||||
const sqlSchedule = `
|
||||
SELECT 1
|
||||
@@ -75,24 +76,28 @@ class Stands {
|
||||
|
||||
async check_entries() {
|
||||
try {
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
// 1. Отримуємо вісників і одразу робимо Map для швидкого пошуку
|
||||
const sheeps = await dbAll(`SELECT id, name FROM sheeps`);
|
||||
if (!sheeps.length) return console.log('There are no sheeps');
|
||||
|
||||
const sheepMap = new Map(sheeps.map(s => [s.id, s.name]));
|
||||
|
||||
const startTomorrow = today.getTime() + 86400000;
|
||||
const startDayAfterTomorrow = today.getTime() + 86400000 * 2;
|
||||
|
||||
// 2. Отримуємо всі записи на завтра
|
||||
const now = new Date();
|
||||
const tomorrow = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
|
||||
const startTomorrow = tomorrow.getTime();
|
||||
const dayAfterTomorrow = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 2);
|
||||
const startDayAfterTomorrow = dayAfterTomorrow.getTime();
|
||||
|
||||
const sqlStands = `
|
||||
SELECT
|
||||
stand_schedule.*,
|
||||
(SELECT stand_list.title FROM stand_list WHERE stand_list.id = stand_schedule.stand_id) AS title
|
||||
stand_list.title
|
||||
FROM
|
||||
stand_schedule
|
||||
LEFT JOIN
|
||||
stand_list ON stand_schedule.stand_id = stand_list.id
|
||||
WHERE
|
||||
stand_schedule.date >= ? AND stand_schedule.date < ?
|
||||
ORDER BY
|
||||
@@ -102,7 +107,7 @@ class Stands {
|
||||
const schedule = await dbAll(sqlStands, [startTomorrow, startDayAfterTomorrow]);
|
||||
if (!schedule.length) return console.log('No active schedule');
|
||||
|
||||
// 2. Угруповання даних (Transform)
|
||||
// 3. Угруповання даних (Transform)
|
||||
const standsData = schedule.reduce((acc, item) => {
|
||||
if (!acc[item.stand_id]) {
|
||||
acc[item.stand_id] = { id: item.stand_id, title: item.title || `Стенд ${sId}`, hours: {}, maxSheepIdx: 0, date: item.date };
|
||||
@@ -115,7 +120,7 @@ class Stands {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// 3. Генерація
|
||||
// 4. Генерація
|
||||
for (const standId in standsData) {
|
||||
const data = standsData[standId];
|
||||
const title = data.title;
|
||||
|
||||
Reference in New Issue
Block a user