|
|
|
@@ -24,17 +24,25 @@ const {
|
|
|
|
|
|
|
|
|
|
|
|
const { getErrorCodeByBrandAndCodeDb } = require("../db/brand_code.db");
|
|
|
|
const { getErrorCodeByBrandAndCodeDb } = require("../db/brand_code.db");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
getDeviceReminderChanelDb,
|
|
|
|
|
|
|
|
getDeviceReminderMonthlyDb,
|
|
|
|
|
|
|
|
getDeviceReminderCustomDb,
|
|
|
|
|
|
|
|
updateDeviceReminderCustomDb,
|
|
|
|
|
|
|
|
updateDeviceReminderMonthlyDb
|
|
|
|
|
|
|
|
} = require("../db/device.db");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
getSparepartsByMonthlyDb,
|
|
|
|
|
|
|
|
getSparepartsByCustomDb
|
|
|
|
|
|
|
|
} = require("../db/sparepart.db");
|
|
|
|
|
|
|
|
|
|
|
|
const { exec } = require("child_process");
|
|
|
|
const { exec } = require("child_process");
|
|
|
|
const util = require("util");
|
|
|
|
const util = require("util");
|
|
|
|
const execPromise = util.promisify(exec);
|
|
|
|
const execPromise = util.promisify(exec);
|
|
|
|
const fs = require('fs').promises;
|
|
|
|
const fs = require('fs').promises;
|
|
|
|
const path = require("path");
|
|
|
|
const path = require("path");
|
|
|
|
const { getDeviceReminderChanelDb,
|
|
|
|
|
|
|
|
getDeviceReminderMonthlyDb,
|
|
|
|
|
|
|
|
getDeviceReminderCustomDb,
|
|
|
|
|
|
|
|
updateDeviceReminderCustomDb
|
|
|
|
|
|
|
|
} = require("../db/device.db");
|
|
|
|
|
|
|
|
const { getSparepartsByMonthlyDb, getSparepartsByCustomDb } = require("../db/sparepart.db");
|
|
|
|
|
|
|
|
const baseDir = path.resolve(__dirname, '../scheduler');
|
|
|
|
const baseDir = path.resolve(__dirname, '../scheduler');
|
|
|
|
const filePath = path.join(baseDir, 'reminder.json');
|
|
|
|
const filePath = path.join(baseDir, 'reminder.json');
|
|
|
|
// const filePathLog = path.join(baseDir, 'log.json');
|
|
|
|
// const filePathLog = path.join(baseDir, 'log.json');
|
|
|
|
@@ -605,8 +613,11 @@ class NotifikasiWaService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async onMonthlyReminder(deviceId) {
|
|
|
|
|
|
|
|
|
|
|
|
async onMonthlyReminder(deviceId, reminderMonthly) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
console.log(`🔄 Memulai onMonthlyReminder untuk device ID: ${deviceId}`);
|
|
|
|
|
|
|
|
|
|
|
|
const paramDb = {
|
|
|
|
const paramDb = {
|
|
|
|
limit: 100,
|
|
|
|
limit: 100,
|
|
|
|
page: 1,
|
|
|
|
page: 1,
|
|
|
|
@@ -614,53 +625,234 @@ class NotifikasiWaService {
|
|
|
|
active: true,
|
|
|
|
active: true,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const allDeviceReminders = await getDeviceReminderMonthlyDb(deviceId);
|
|
|
|
// 1. Validasi device
|
|
|
|
|
|
|
|
console.log(`📡 Mengambil data device dengan ID: ${deviceId}`);
|
|
|
|
|
|
|
|
const devices = await getDeviceReminderMonthlyDb(deviceId);
|
|
|
|
|
|
|
|
|
|
|
|
if (!allDeviceReminders || allDeviceReminders.length === 0) {
|
|
|
|
if (!devices || devices.length === 0) {
|
|
|
|
return { success: false, message: 'Tidak ada data device.' };
|
|
|
|
console.error(`❌ Device dengan ID ${deviceId} tidak ditemukan`);
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: `Device dengan ID ${deviceId} tidak ditemukan di database`
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const now = dayjs().tz(timeZone);
|
|
|
|
const device = devices[0];
|
|
|
|
const currentYear = dayjs().tz(timeZone).year();
|
|
|
|
const deviceName = device.device_name;
|
|
|
|
const currentMonth = dayjs().tz(timeZone).month() + 1;
|
|
|
|
const currentDeviceId = device.device_id;
|
|
|
|
|
|
|
|
|
|
|
|
for (const deviceReminder of allDeviceReminders) {
|
|
|
|
console.log(`✅ Device ditemukan: ${deviceName} (ID: ${currentDeviceId})`);
|
|
|
|
|
|
|
|
|
|
|
|
if (deviceReminder?.reminder_at_monthly) {
|
|
|
|
// 2. Validasi dan update reminder_at_monthly jika diperlukan
|
|
|
|
const deviceName = deviceReminder.device_name ?? '-';
|
|
|
|
let targetReminderTime = device.reminder_at_monthly;
|
|
|
|
const currentDeviceId = deviceReminder.device_id;
|
|
|
|
console.log(`📅 Reminder time dari DB: ${targetReminderTime}`);
|
|
|
|
|
|
|
|
|
|
|
|
const reminderAt = dayjs.tz(
|
|
|
|
if (reminderMonthly) {
|
|
|
|
deviceReminder.reminder_at_monthly,
|
|
|
|
console.log(`📝 Mengupdate reminder time ke: ${reminderMonthly}`);
|
|
|
|
timeZone
|
|
|
|
const isValidDate = dayjs.tz(reminderMonthly, this.timeZone).isValid();
|
|
|
|
|
|
|
|
if (!isValidDate) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'Format reminderMonthly tidak valid. Gunakan format YYYY-MM-DD HH:mm:ss'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updatedDevice = await updateDeviceReminderMonthlyDb(deviceId, reminderMonthly);
|
|
|
|
|
|
|
|
if (!updatedDevice) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'Gagal mengupdate reminder monthly.'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
targetReminderTime = reminderMonthly;
|
|
|
|
|
|
|
|
console.log(`✅ Reminder time berhasil diupdate ke: ${targetReminderTime}`);
|
|
|
|
|
|
|
|
} else if (!targetReminderTime) {
|
|
|
|
|
|
|
|
console.log(`⚠️ Tidak ada reminder time, setting default ke sekarang + 1 jam`);
|
|
|
|
|
|
|
|
const reminderTime = dayjs().tz(this.timeZone).add(1, 'hour').format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
|
|
|
const updatedDevice = await updateDeviceReminderMonthlyDb(deviceId, reminderTime);
|
|
|
|
|
|
|
|
if (!updatedDevice) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'Gagal mengupdate reminder monthly dengan default time.'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
targetReminderTime = reminderTime;
|
|
|
|
|
|
|
|
console.log(`✅ Default reminder time: ${targetReminderTime}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`📅 Target reminder time: ${targetReminderTime}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. Parse target reminder time
|
|
|
|
|
|
|
|
const reminderAt = dayjs.tz(targetReminderTime, this.timeZone);
|
|
|
|
|
|
|
|
const now = dayjs().tz(this.timeZone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`🕐 Waktu sekarang: ${now.format('YYYY-MM-DD HH:mm:ss')}`);
|
|
|
|
|
|
|
|
console.log(`🕐 Waktu reminder: ${reminderAt.format('YYYY-MM-DD HH:mm:ss')}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. Jika sudah lewat atau sama, langsung kirim (sama seperti onCustomReminder)
|
|
|
|
|
|
|
|
const isEndDatePassed = now.isAfter(reminderAt) || now.isSame(reminderAt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isEndDatePassed) {
|
|
|
|
|
|
|
|
console.log(`⏰ Reminder time sudah terlewati, mengirim reminder sekarang untuk ${deviceName}`);
|
|
|
|
|
|
|
|
const sendResult = await this.sendMonthlyReminderNow(
|
|
|
|
|
|
|
|
currentDeviceId,
|
|
|
|
|
|
|
|
deviceName,
|
|
|
|
|
|
|
|
reminderAt
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return sendResult;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 5. Jika belum waktunya, jadwalkan cron job (sama seperti onCustomReminder)
|
|
|
|
|
|
|
|
console.log(`⏰ Menjadwalkan reminder untuk ${deviceName} pada ${reminderAt.format('YYYY-MM-DD HH:mm:ss')}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Stop cron job lama jika ada
|
|
|
|
|
|
|
|
this.stopCronJob(currentDeviceId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Schedule cron job
|
|
|
|
|
|
|
|
const scheduleResult = await this.scheduleMonthlyReminderJob(
|
|
|
|
|
|
|
|
currentDeviceId,
|
|
|
|
|
|
|
|
deviceName,
|
|
|
|
|
|
|
|
reminderAt
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const nowKey = now.format('MM-DD HH:mm');
|
|
|
|
return {
|
|
|
|
const reminderKey = reminderAt.format('MM-DD HH:mm');
|
|
|
|
success: true,
|
|
|
|
|
|
|
|
message: `Reminder berhasil dijadwalkan untuk device ${deviceName}`,
|
|
|
|
|
|
|
|
schedule: scheduleResult,
|
|
|
|
|
|
|
|
nextRun: scheduleResult.nextRun
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const isTriggered = nowKey >= reminderKey;
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error('❌ Error onMonthlyReminder:', error);
|
|
|
|
|
|
|
|
console.error('❌ Stack trace:', error.stack);
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'Error pada onMonthlyReminder: ' + error.message,
|
|
|
|
|
|
|
|
error: error,
|
|
|
|
|
|
|
|
stack: error.stack
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isTriggered) {
|
|
|
|
async scheduleMonthlyReminderJob(deviceId, deviceName, reminderAt) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const now = dayjs().tz(this.timeZone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const targetTime = reminderAt.clone()
|
|
|
|
|
|
|
|
.set('second', 0)
|
|
|
|
|
|
|
|
.set('millisecond', 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const nextRun = targetTime.format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Reminder untuk ${deviceName} dijadwalkan pada ${nextRun}`);
|
|
|
|
|
|
|
|
console.log(`Reminder At: ${reminderAt.format('YYYY-MM-DD HH:mm:ss')}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const timeoutId = setTimeout(async () => {
|
|
|
|
|
|
|
|
console.log(`Waktu pengiriman tiba untuk ${deviceName} pada ${dayjs().tz(this.timeZone).format('YYYY-MM-DD HH:mm:ss')}`);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await this.sendMonthlyReminderNow(deviceId, deviceName, reminderAt);
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error(`Gagal mengirim reminder untuk ${deviceName}:`, error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.cronJobs.set(deviceId, {
|
|
|
|
|
|
|
|
timeoutId,
|
|
|
|
|
|
|
|
nextRun,
|
|
|
|
|
|
|
|
reminderAt: reminderAt.format('YYYY-MM-DD HH:mm:ss')
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cronExpression = `${reminderAt.minute()} ${reminderAt.hour()} * * *`;
|
|
|
|
|
|
|
|
console.log(`Backup cron akan berjalan setiap hari pada ${reminderAt.hour()}:${reminderAt.minute()}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cronTask = cron.schedule(cronExpression, async () => {
|
|
|
|
|
|
|
|
console.log(`Backup cron job berjalan untuk ${deviceName} pada ${dayjs().tz(this.timeZone).format('YYYY-MM-DD HH:mm:ss')}`);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const now = dayjs().tz(this.timeZone);
|
|
|
|
|
|
|
|
const isEndDatePassed = now.isAfter(reminderAt) || now.isSame(reminderAt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isEndDatePassed) {
|
|
|
|
|
|
|
|
const currentMonth = now.month() + 1;
|
|
|
|
|
|
|
|
const checkNotifExist = await getReminderNotificationErrorByMonthlyDb(
|
|
|
|
|
|
|
|
parseInt(`${currentMonth}`),
|
|
|
|
|
|
|
|
currentMonth,
|
|
|
|
|
|
|
|
deviceId
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!checkNotifExist) {
|
|
|
|
|
|
|
|
await this.sendMonthlyReminderNow(deviceId, deviceName, reminderAt);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.log(`Reminder untuk ${deviceName} sudah pernah dikirim`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cronTask.stop();
|
|
|
|
|
|
|
|
this.cronJobs.delete(`cron_${deviceId}`);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.log(`Menunggu reminder untuk ${deviceName}: ${reminderAt.format('YYYY-MM-DD HH:mm:ss')}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error(`Backup cron job gagal untuk ${deviceName}:`, error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
|
|
|
timezone: this.timeZone
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.cronJobs.set(`cron_${deviceId}`, {
|
|
|
|
|
|
|
|
cronTask,
|
|
|
|
|
|
|
|
nextRun,
|
|
|
|
|
|
|
|
reminderAt: reminderAt.format('YYYY-MM-DD HH:mm:ss')
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
nextRun,
|
|
|
|
|
|
|
|
targetDate: targetTime.format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
|
|
|
reminderAt: reminderAt.format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
|
|
|
cronExpression: cronExpression,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error('Error scheduling monthly reminder:', error);
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async sendMonthlyReminderNow(deviceId, deviceName, reminderAt) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
console.log(`Mengirim reminder untuk ${deviceName}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const paramDb = {
|
|
|
|
|
|
|
|
limit: 100,
|
|
|
|
|
|
|
|
page: 1,
|
|
|
|
|
|
|
|
criteria: "",
|
|
|
|
|
|
|
|
active: true,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const now = dayjs().tz(this.timeZone);
|
|
|
|
|
|
|
|
const currentMonth = now.month() + 1;
|
|
|
|
|
|
|
|
const currentYear = now.year();
|
|
|
|
const monthlyCode = parseInt(`${currentMonth}`);
|
|
|
|
const monthlyCode = parseInt(`${currentMonth}`);
|
|
|
|
|
|
|
|
|
|
|
|
const checkNotifExist = await getReminderNotificationErrorByMonthlyDb(
|
|
|
|
const checkNotifExist = await getReminderNotificationErrorByMonthlyDb(
|
|
|
|
monthlyCode,
|
|
|
|
monthlyCode,
|
|
|
|
currentMonth,
|
|
|
|
currentMonth,
|
|
|
|
currentDeviceId
|
|
|
|
deviceId
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (checkNotifExist) {
|
|
|
|
if (checkNotifExist) {
|
|
|
|
throw new Error(`Reminder untuk device ${deviceName} device id ${currentDeviceId} bulan ${currentMonth} sudah pernah dibuat.`);
|
|
|
|
console.log(`Reminder untuk ${deviceName} bulan ${currentMonth} sudah pernah dibuat`);
|
|
|
|
continue;
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: `Reminder untuk device ${deviceName} sudah pernah dibuat.`
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const spareparts = await getSparepartsByMonthlyDb(currentMonth);
|
|
|
|
const spareparts = await getSparepartsByMonthlyDb(currentMonth);
|
|
|
|
|
|
|
|
const sparepartList = spareparts && spareparts.length > 0
|
|
|
|
let sparepartList = "";
|
|
|
|
? "\n\nDaftar sparepart yang perlu diperiksa:\n" +
|
|
|
|
if (spareparts && spareparts.length > 0) {
|
|
|
|
spareparts.map((sp, idx) => `${idx + 1}. ${sp.sparepart_name || 'Sparepart'}`).join('\n')
|
|
|
|
sparepartList = "\n\nDaftar sparepart yang perlu diperiksa:\n" +
|
|
|
|
: "";
|
|
|
|
spareparts.map((sp, idx) => `${idx + 1}. ${sp.sparepart_name || 'Sparepart'}`).join('\n');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
const data = {
|
|
|
|
error_code_id: monthlyCode,
|
|
|
|
error_code_id: monthlyCode,
|
|
|
|
@@ -669,18 +861,26 @@ class NotifikasiWaService {
|
|
|
|
is_delivered: 0,
|
|
|
|
is_delivered: 0,
|
|
|
|
is_read: 0,
|
|
|
|
is_read: 0,
|
|
|
|
is_active: 1,
|
|
|
|
is_active: 1,
|
|
|
|
message_error_issue: `reminder device ${deviceName} device_id: ${currentDeviceId} in month ${currentMonth}`,
|
|
|
|
message_error_issue: `reminder monthly device ${deviceName} in month ${currentMonth}`,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const resultNotificationError = await InsertNotificationErrorDb(data);
|
|
|
|
const resultNotificationError = await InsertNotificationErrorDb(data);
|
|
|
|
|
|
|
|
if (!resultNotificationError) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'Gagal menyimpan notifikasi error'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const results = await getAllContactDb(paramDb);
|
|
|
|
const results = await getAllContactDb(paramDb);
|
|
|
|
const dataUsers = results.data;
|
|
|
|
const dataUsers = results.data;
|
|
|
|
|
|
|
|
|
|
|
|
let isSendNotification = false;
|
|
|
|
let isSendNotification = false;
|
|
|
|
|
|
|
|
let successCount = 0;
|
|
|
|
|
|
|
|
let failCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (const dataUser of dataUsers) {
|
|
|
|
for (const dataUser of dataUsers) {
|
|
|
|
if (dataUser.is_active) {
|
|
|
|
if (dataUser.is_active) {
|
|
|
|
|
|
|
|
|
|
|
|
const tokenRedirect = await generateTokenRedirect(
|
|
|
|
const tokenRedirect = await generateTokenRedirect(
|
|
|
|
dataUser.contact_phone,
|
|
|
|
dataUser.contact_phone,
|
|
|
|
dataUser.contact_name,
|
|
|
|
dataUser.contact_name,
|
|
|
|
@@ -694,7 +894,7 @@ class NotifikasiWaService {
|
|
|
|
`Hai ${dataUser.contact_name || "-"},\n\n` +
|
|
|
|
`Hai ${dataUser.contact_name || "-"},\n\n` +
|
|
|
|
`Diberitahukan bahwa terdapat sparepart pada device "${deviceName}" ` +
|
|
|
|
`Diberitahukan bahwa terdapat sparepart pada device "${deviceName}" ` +
|
|
|
|
`yang telah memasuki jadwal perawatan bulanan untuk bulan ${currentMonth} pada tahun ${currentYear}.${sparepartList}\n\n` +
|
|
|
|
`yang telah memasuki jadwal perawatan bulanan untuk bulan ${currentMonth} pada tahun ${currentYear}.${sparepartList}\n\n` +
|
|
|
|
`Silakan segera lakukan pengecekan dan perawatan untuk memastikan kinerja tetap optimal.`;
|
|
|
|
`Silakan segera lakukan pengecekan dan perawatan untuk memastikan kinerja tetap optimal.`
|
|
|
|
|
|
|
|
|
|
|
|
const param = {
|
|
|
|
const param = {
|
|
|
|
idData: resultNotificationError.notification_error_id,
|
|
|
|
idData: resultNotificationError.notification_error_id,
|
|
|
|
@@ -716,15 +916,17 @@ class NotifikasiWaService {
|
|
|
|
param.bodyMessage
|
|
|
|
param.bodyMessage
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (resultNotificationErrorUser && resultNotificationErrorUser.length > 0) {
|
|
|
|
await updateNotificationErrorUserDb(
|
|
|
|
await updateNotificationErrorUserDb(
|
|
|
|
resultNotificationErrorUser[0].notification_error_user_id,
|
|
|
|
resultNotificationErrorUser[0].notification_error_user_id,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
is_send: resultSend.success,
|
|
|
|
is_send: resultSend.success,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (resultSend.success) {
|
|
|
|
if (resultSend.success) {
|
|
|
|
isSendNotification = resultSend.success;
|
|
|
|
isSendNotification = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -741,7 +943,7 @@ class NotifikasiWaService {
|
|
|
|
notification_log: resultNotificationError.notification_error_id,
|
|
|
|
notification_log: resultNotificationError.notification_error_id,
|
|
|
|
error_code_id: data['error_code_id'],
|
|
|
|
error_code_id: data['error_code_id'],
|
|
|
|
error_chanel: data['error_chanel'],
|
|
|
|
error_chanel: data['error_chanel'],
|
|
|
|
start_at: reminderAt.format('HH:mm'),
|
|
|
|
start_at: now.format('HH:mm'),
|
|
|
|
interval: 1,
|
|
|
|
interval: 1,
|
|
|
|
max: 3,
|
|
|
|
max: 3,
|
|
|
|
active: 1,
|
|
|
|
active: 1,
|
|
|
|
@@ -750,18 +952,20 @@ class NotifikasiWaService {
|
|
|
|
last_run_indo: now.format('DD-MM-YYYY HH:mm:ss'),
|
|
|
|
last_run_indo: now.format('DD-MM-YYYY HH:mm:ss'),
|
|
|
|
next_run: null,
|
|
|
|
next_run: null,
|
|
|
|
next_run_indo: null,
|
|
|
|
next_run_indo: null,
|
|
|
|
message: `Reminder untuk ${deviceName} bulan ${currentMonth} telah dijalankan.`,
|
|
|
|
message: `Reminder monthly untuk ${deviceName} bulan ${currentMonth} telah dijalankan.`,
|
|
|
|
}, false);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
this.stopCronJob(deviceId);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { success: true, message: "Reminder has been sent." };
|
|
|
|
console.log(`Reminder berhasil dikirim untuk ${deviceName}`);
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: true,
|
|
|
|
|
|
|
|
message: "Reminder has been sent.",
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Error on Monthly Reminder:', err);
|
|
|
|
console.error('Error sending monthly reminder now:', error);
|
|
|
|
throw err;
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|